summaryrefslogtreecommitdiff
path: root/apps/talk.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/talk.c')
-rw-r--r--apps/talk.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/apps/talk.c b/apps/talk.c
index 89ab3901c4..3b7ab2a03f 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -117,6 +117,8 @@ static long size_for_thumbnail; /* leftover buffer size for it */
117static struct voicefile* p_voicefile; /* loaded voicefile */ 117static struct voicefile* p_voicefile; /* loaded voicefile */
118static bool has_voicefile; /* a voicefile file is present */ 118static bool has_voicefile; /* a voicefile file is present */
119static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */ 119static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
120/* enqueue next utterance even if enqueue is false. */
121static bool force_enqueue_next;
120static int queue_write; /* write index of queue, by application */ 122static int queue_write; /* write index of queue, by application */
121static int queue_read; /* read index of queue, by ISR context */ 123static int queue_read; /* read index of queue, by ISR context */
122static int sent; /* how many bytes handed over to playback, owned by ISR */ 124static int sent; /* how many bytes handed over to playback, owned by ISR */
@@ -134,7 +136,6 @@ static int talk_menu_disable; /* if non-zero, temporarily disable voice UI (not
134 136
135static void load_voicefile(void); 137static void load_voicefile(void);
136static void mp3_callback(unsigned char** start, size_t* size); 138static void mp3_callback(unsigned char** start, size_t* size);
137static int shutup(void);
138static int queue_clip(unsigned char* buf, long size, bool enqueue); 139static int queue_clip(unsigned char* buf, long size, bool enqueue);
139static int open_voicefile(void); 140static int open_voicefile(void);
140static unsigned char* get_clip(long id, long* p_size); 141static unsigned char* get_clip(long id, long* p_size);
@@ -267,6 +268,13 @@ load_err:
267} 268}
268 269
269 270
271/* Are more voice clips queued and waiting? */
272bool is_voice_queued()
273{
274 return !!QUEUE_LEVEL;
275}
276
277
270/* called in ISR context if mp3 data got consumed */ 278/* called in ISR context if mp3 data got consumed */
271static void mp3_callback(unsigned char** start, size_t* size) 279static void mp3_callback(unsigned char** start, size_t* size)
272{ 280{
@@ -321,7 +329,7 @@ re_check:
321} 329}
322 330
323/* stop the playback and the pending clips */ 331/* stop the playback and the pending clips */
324static int shutup(void) 332static int do_shutup(void)
325{ 333{
326#if CONFIG_CODEC != SWCODEC 334#if CONFIG_CODEC != SWCODEC
327 unsigned char* pos; 335 unsigned char* pos;
@@ -387,6 +395,13 @@ static int shutup(void)
387 return 0; 395 return 0;
388} 396}
389 397
398/* Shutup the voice, except if force_enqueue_next is set. */
399static int shutup(void)
400{
401 if (!force_enqueue_next)
402 return do_shutup();
403 return 0;
404}
390 405
391/* schedule a clip, at the end or discard the existing queue */ 406/* schedule a clip, at the end or discard the existing queue */
392static int queue_clip(unsigned char* buf, long size, bool enqueue) 407static int queue_clip(unsigned char* buf, long size, bool enqueue)
@@ -395,6 +410,9 @@ static int queue_clip(unsigned char* buf, long size, bool enqueue)
395 410
396 if (!enqueue) 411 if (!enqueue)
397 shutup(); /* cut off all the pending stuff */ 412 shutup(); /* cut off all the pending stuff */
413 /* Something is being enqueued, force_enqueue_next override is no
414 longer in effect. */
415 force_enqueue_next = false;
398 416
399 if (!size) 417 if (!size)
400 return 0; /* safety check */ 418 return 0; /* safety check */
@@ -617,6 +635,26 @@ int talk_id(long id, bool enqueue)
617 return 0; 635 return 0;
618} 636}
619 637
638/* Speaks zero or more IDs (from an array). */
639int talk_idarray(long *ids, bool enqueue)
640{
641 int r;
642 if(!ids)
643 return 0;
644 while(*ids != TALK_FINAL_ID)
645 {
646 if((r = talk_id(*ids++, enqueue)) <0)
647 return r;
648 enqueue = true;
649 }
650 return 0;
651}
652
653/* Make sure the current utterance is not interrupted by the next one. */
654void talk_force_enqueue_next(void)
655{
656 force_enqueue_next = true;
657}
620 658
621/* play a thumbnail from file */ 659/* play a thumbnail from file */
622int talk_file(const char* filename, bool enqueue) 660int talk_file(const char* filename, bool enqueue)