Merge pull request #1523 from mochouinard/master

[core] Add support to phrase play-file to set a volume attribute
This commit is contained in:
Andrey Volk 2022-02-25 01:26:16 +03:00 committed by GitHub
commit 4b580a07c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -356,6 +356,7 @@ struct switch_file_handle {
switch_size_t samples_in; switch_size_t samples_in;
switch_size_t samples_out; switch_size_t samples_out;
int32_t vol; int32_t vol;
int32_t volgranular;
switch_audio_resampler_t *resampler; switch_audio_resampler_t *resampler;
switch_buffer_t *buffer; switch_buffer_t *buffer;
switch_byte_t *dbuf; switch_byte_t *dbuf;

View File

@ -251,7 +251,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro_event(switch_core_sessio
module_name); module_name);
if (!strcasecmp(func, "play-file")) { if (!strcasecmp(func, "play-file")) {
status = switch_ivr_play_file(session, NULL, odata, args); char *volume_str = (char *) switch_xml_attr_soft(action, "volume");
switch_file_handle_t pfh = { 0 };
if (volume_str && switch_is_number(volume_str)) {
int32_t volume = atoi(volume_str);
switch_normalize_volume_granular(volume)
pfh.volgranular = volume;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Setting playback volume to %d\n", pfh.volgranular);
}
status = switch_ivr_play_file(session, &pfh, odata, args);
} else if (!strcasecmp(func, "phrase")) { } else if (!strcasecmp(func, "phrase")) {
char *name = (char *) switch_xml_attr_soft(action, "phrase"); char *name = (char *) switch_xml_attr_soft(action, "phrase");
status = switch_ivr_phrase_macro(session, name, odata, chan_lang, args); status = switch_ivr_phrase_macro(session, name, odata, chan_lang, args);
@ -1957,8 +1967,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} }
#endif #endif
#endif #endif
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->vol) { if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
switch_change_sln_volume(write_frame.data, write_frame.datalen / 2, fh->vol); if (fh->volgranular) {
switch_change_sln_volume_granular(write_frame.data, write_frame.datalen / 2, fh->volgranular);
} else if (fh->vol) { /* deprecated 2022-Q1 */
switch_change_sln_volume(write_frame.data, write_frame.datalen / 2, fh->vol);
}
} }
/* write silence while dmachine is in reading state */ /* write silence while dmachine is in reading state */