diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-01-10 20:25:44 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-01-10 20:25:44 +0000 |
commit | 754d083c48e80cb412d850cd451d469e74fcef62 (patch) | |
tree | 953b881651284bbe8d044944d4e7c3368a4f118c /apps/app_speech_utils.c | |
parent | d86e80721ccee4727d829cb0d9659642ee411f36 (diff) |
Merge speech-multi branch which adds support for joining multiple sound files together to be played one after another in SpeechBackground.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@50433 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_speech_utils.c')
-rw-r--r-- | apps/app_speech_utils.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/apps/app_speech_utils.c b/apps/app_speech_utils.c index 525aa0af4..8bd07e359 100644 --- a/apps/app_speech_utils.c +++ b/apps/app_speech_utils.c @@ -487,24 +487,18 @@ static int speech_processing_sound(struct ast_channel *chan, void *data) /*! \brief Helper function used by speech_background to playback a soundfile */ static int speech_streamfile(struct ast_channel *chan, const char *filename, const char *preflang) { - struct ast_filestream *fs; - struct ast_filestream *vfs=NULL; - - fs = ast_openstream(chan, filename, preflang); - if (fs) - vfs = ast_openvstream(chan, filename, preflang); - if (fs){ - if (ast_applystream(chan, fs)) - return -1; - if (vfs && ast_applystream(chan, vfs)) - return -1; - if (ast_playstream(fs)) - return -1; - if (vfs && ast_playstream(vfs)) - return -1; - return 0; - } - return -1; + struct ast_filestream *fs = NULL; + + if (!(fs = ast_openstream(chan, filename, preflang))) + return -1; + + if (ast_applystream(chan, fs)) + return -1; + + if (ast_playstream(fs)) + return -1; + + return 0; } /*! \brief SpeechBackground(Sound File|Timeout) Dialplan Application */ @@ -519,7 +513,7 @@ static int speech_background(struct ast_channel *chan, void *data) char dtmf[AST_MAX_EXTENSION] = ""; time_t start, current; struct ast_datastore *datastore = NULL; - char *argv[2], *args = NULL, *filename = NULL, tmp[2] = ""; + char *argv[2], *args = NULL, *filename_tmp = NULL, *filename = NULL, tmp[2] = ""; args = ast_strdupa(data); @@ -549,27 +543,30 @@ static int speech_background(struct ast_channel *chan, void *data) argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])); if (argc > 0) { /* Yay sound file */ - filename = argv[0]; + filename_tmp = ast_strdupa(argv[0]); if (argv[1] != NULL) timeout = atoi(argv[1]); } - /* Start streaming the file if possible and specified */ - if (filename != NULL && ast_streamfile(chan, filename, chan->language)) { - /* An error occured while streaming */ - ast_set_read_format(chan, oldreadformat); - ast_module_user_remove(u); - return -1; - } - /* Before we go into waiting for stuff... make sure the structure is ready, if not - start it again */ if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) { ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); ast_speech_start(speech); } + /* Ensure no streams are currently running */ + ast_stopstream(chan); + /* Okay it's streaming so go into a loop grabbing frames! */ while (done == 0) { + /* If the filename is null and stream is not running, start up a new sound file */ + if ((chan->streamid == -1 && chan->timingfunc == NULL) && (filename = strsep(&filename_tmp, "&"))) { + /* Discard old stream information */ + ast_stopstream(chan); + /* Start new stream */ + speech_streamfile(chan, filename, chan->language); + } + /* Run scheduled stuff */ ast_sched_runq(chan->sched); |