2004-03-14 21:33:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2004 Jörg Hohensohn
|
2004-03-14 21:33:53 +00:00
|
|
|
*
|
|
|
|
* This module collects the Talkbox and voice UI functions.
|
|
|
|
* (Talkbox reads directory names from mp3 clips called thumbnails,
|
|
|
|
* the voice UI lets menus and screens "talk" from a voicefont in memory.
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-03-14 21:33:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __TALK_H__
|
|
|
|
#define __TALK_H__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2007-11-20 19:50:52 +00:00
|
|
|
#include <inttypes.h>
|
2007-10-07 08:12:01 +00:00
|
|
|
#include "time.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
|
2007-11-18 17:12:19 +00:00
|
|
|
#define VOICE_VERSION 400 /* 4.00 - if you change this, change it in voicefont too */
|
2007-11-15 19:32:15 +00:00
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
enum {
|
2006-09-26 17:44:43 +00:00
|
|
|
/* See array "unit_voiced" in talk.c function "talk_value" */
|
2004-03-19 22:15:53 +00:00
|
|
|
UNIT_INT = 1, /* plain number */
|
|
|
|
UNIT_SIGNED, /* number with mandatory sign (even if positive) */
|
|
|
|
UNIT_MS, /* milliseconds */
|
|
|
|
UNIT_SEC, /* seconds */
|
|
|
|
UNIT_MIN, /* minutes */
|
|
|
|
UNIT_HOUR, /* hours */
|
|
|
|
UNIT_KHZ, /* kHz */
|
|
|
|
UNIT_DB, /* dB, mandatory sign */
|
|
|
|
UNIT_PERCENT, /* % */
|
2004-03-20 16:49:58 +00:00
|
|
|
UNIT_MAH, /* milliAmp hours */
|
|
|
|
UNIT_PIXEL, /* pixels */
|
|
|
|
UNIT_PER_SEC, /* per second */
|
|
|
|
UNIT_HERTZ, /* hertz */
|
2006-07-22 17:23:05 +00:00
|
|
|
UNIT_MB, /* Megabytes */
|
2006-08-28 22:38:41 +00:00
|
|
|
UNIT_KBIT, /* kilobits per sec */
|
2007-08-18 23:03:03 +00:00
|
|
|
UNIT_PM_TICK, /* peak meter units per tick */
|
2011-02-20 15:23:18 +00:00
|
|
|
UNIT_TIME, /* time duration/interval in seconds, says hours,mins,secs */
|
2018-10-30 13:45:26 +00:00
|
|
|
UNIT_DATEYEAR,/* for 1999 say nineteen ninety nine */
|
2004-03-19 22:15:53 +00:00
|
|
|
UNIT_LAST /* END MARKER */
|
|
|
|
};
|
|
|
|
|
2006-09-26 17:44:43 +00:00
|
|
|
#define UNIT_SHIFT (32-5) /* this many bits left from UNIT_xx enum */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
2008-04-19 13:19:04 +00:00
|
|
|
#define DECIMAL_SHIFT (32 - 8)
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
/* make a "talkable" ID from number + unit
|
|
|
|
unit is upper 4 bits, number the remaining (in regular 2's complement) */
|
2017-02-13 16:07:52 +00:00
|
|
|
#define TALK_ID(n,u) (((long)(u))<<UNIT_SHIFT | ((n) & ~(-1L<<DECIMAL_SHIFT)))
|
2004-03-19 22:15:53 +00:00
|
|
|
|
2008-04-19 13:19:04 +00:00
|
|
|
/* make a "talkable" ID from a decimal number + unit, the decimal number
|
2008-04-20 11:02:42 +00:00
|
|
|
is represented like x*10^d where d is the number of decimal digits */
|
2008-04-19 13:19:04 +00:00
|
|
|
#define TALK_ID_DECIMAL(n,d,u) (((long)(u))<<UNIT_SHIFT |\
|
|
|
|
((long)(d))<<DECIMAL_SHIFT |\
|
|
|
|
((n) & ~(-1L<<DECIMAL_SHIFT)))
|
|
|
|
|
2004-07-23 23:01:20 +00:00
|
|
|
/* convenience macro to have both virtual pointer and ID as arguments */
|
|
|
|
#define STR(id) ID2P(id), id
|
2004-03-19 22:15:53 +00:00
|
|
|
|
2013-05-30 09:24:16 +00:00
|
|
|
/* Policy values for how hard to try to keep the talk/voice buffers.
|
|
|
|
* Affects how genereous talk.c is when it's asked for memory in
|
|
|
|
* shrink_callbacks().
|
|
|
|
*
|
|
|
|
* I.e. setting the policy to TALK_BUFFER_LOOSE, it will happily give its
|
|
|
|
* entire bufer away if asked for, e.g. due to a another module
|
|
|
|
* calling core_alloc_maximum(), TALK_BUFFER_HOLD on the other hand will
|
|
|
|
* make it keep the buffers so that a call to core_alloc_maximum() does not
|
|
|
|
* stop the speech-interface.
|
|
|
|
*/
|
|
|
|
enum talk_buffer_policies {
|
|
|
|
TALK_BUFFER_DEFAULT,
|
|
|
|
TALK_BUFFER_LOOSE,
|
|
|
|
TALK_BUFFER_HOLD,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This sets the actual policy. Call this before core_alloc_maximum() to
|
|
|
|
* get the desired outcome */
|
|
|
|
void talk_buffer_set_policy(int policy);
|
|
|
|
|
2004-10-21 18:34:48 +00:00
|
|
|
/* publish these strings, so they're stored only once (better than #define) */
|
2004-10-06 21:37:46 +00:00
|
|
|
extern const char* const dir_thumbnail_name; /* "_dirname.talk" */
|
2004-10-21 18:34:48 +00:00
|
|
|
extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
2004-03-14 21:33:53 +00:00
|
|
|
void talk_init(void);
|
2005-08-20 11:13:19 +00:00
|
|
|
int talk_get_bufsize(void); /* get the loaded voice file size */
|
2011-08-14 15:13:00 +00:00
|
|
|
size_t talkbuf_init(char* bufstart);
|
2007-08-06 13:08:36 +00:00
|
|
|
bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
|
2007-11-20 19:50:52 +00:00
|
|
|
int talk_id(int32_t id, bool enqueue); /* play a voice ID from voicefont */
|
2008-07-15 14:55:31 +00:00
|
|
|
/* play a thumbnail from file */
|
|
|
|
int talk_file(const char *root, const char *dir, const char *file,
|
2008-09-29 16:29:51 +00:00
|
|
|
const char *ext, const long *prefix_ids, bool enqueue);
|
2008-07-15 14:55:31 +00:00
|
|
|
/* play file's thumbnail or spell name */
|
|
|
|
int talk_file_or_spell(const char *dirname, const char* filename,
|
2008-09-29 16:29:51 +00:00
|
|
|
const long *prefix_ids, bool enqueue);
|
2019-02-04 01:12:50 +00:00
|
|
|
|
2008-07-15 14:55:31 +00:00
|
|
|
/* play dir's thumbnail or spell name */
|
|
|
|
int talk_dir_or_spell(const char* filename,
|
2008-09-29 16:29:51 +00:00
|
|
|
const long *prefix_ids, bool enqueue);
|
2019-02-04 01:12:50 +00:00
|
|
|
|
2018-10-30 13:45:26 +00:00
|
|
|
/* play thumbnails for each components of full path, or spell */
|
|
|
|
int talk_fullpath(const char* path, bool enqueue);
|
2005-02-12 11:26:36 +00:00
|
|
|
int talk_number(long n, bool enqueue); /* say a number */
|
|
|
|
int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
|
2008-04-19 13:19:04 +00:00
|
|
|
int talk_value_decimal(long n, int unit, int decimals, bool enqueue);
|
2004-08-18 01:09:31 +00:00
|
|
|
int talk_spell(const char* spell, bool enqueue); /* spell a string */
|
2008-03-25 15:24:03 +00:00
|
|
|
void talk_setting(const void *global_settings_variable); /* read a setting */
|
2007-10-19 15:31:42 +00:00
|
|
|
void talk_disable(bool disable); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
|
|
|
|
void talk_force_shutup(void); /* kill voice unconditionally */
|
|
|
|
void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
|
2007-08-06 15:01:45 +00:00
|
|
|
|
2008-04-20 11:02:42 +00:00
|
|
|
/* helper function for speaking fractional numbers */
|
|
|
|
void talk_fractional(char *tbuf, int value, int unit);
|
|
|
|
|
2008-09-29 16:29:51 +00:00
|
|
|
void talk_time(const struct tm *tm, bool enqueue);
|
|
|
|
void talk_date(const struct tm *tm, bool enqueue);
|
2007-10-07 08:12:01 +00:00
|
|
|
|
Auto-Ranging Time Formatting For Menus (hh:mm:ss:mss)
Unifies time formatting in settings_list.c allows time format to
display as HH:MM:SS.MSS or any consecutive combination thereof
(hh:mm:ss, mm:ss, mm:ss.mss, ss.mss, hh, mm, ss ,mss)
works in INT and TABLE settings with the addition of flag 'F_TIME_SETTING'
Time is auto-ranged dependent on value
Adds talk_time_intervals to allow time values to be spoken similar to
display format: x Hours, x Minutes, x Seconds, x Milliseconds
Table lookups merged or removed from recording, clip meter and lcd timeout
-String_Choice replaced with TABLE_SETTING or INT_SETTING for these
functions as well, cleaned-up cfg_vals that get saved to cfgfile
RTL Languages ARE supported
Negative values ARE supported
Backlight on/off are now Always and Never to share formatter with LCD
Timeout
Added flag to allow ranged units to be locked to a minimum index
Added flag to allow leading zero to be supressed from the largest unit
merged talk_time_unit() and talk_time_intervals()
optimized time_split()
optimized format_time_auto()
Backlight time-out list same as original
Change-Id: I59027c62d3f2956bd16fdcc1a48b2ac32c084abd
2018-12-18 04:27:55 +00:00
|
|
|
/* speaks hr, min, sec, ms; unit_idx is lowest or base unit of the time value */
|
|
|
|
int talk_time_intervals(long time, int unit_idx, bool enqueue);
|
|
|
|
|
2007-08-06 15:01:45 +00:00
|
|
|
/* This (otherwise invalid) ID signals the end of the array. */
|
|
|
|
#define TALK_FINAL_ID LANG_LAST_INDEX_IN_ARRAY
|
2019-10-15 02:42:19 +00:00
|
|
|
#define TALK_FINAL_ID_VOICEONLY LANG_LAST_VOICEONLY_INDEX_IN_ARRAY
|
2007-08-06 13:08:36 +00:00
|
|
|
/* Enqueue next utterance even if enqueue parameter is false: don't
|
|
|
|
interrupt the current utterance. */
|
|
|
|
void talk_force_enqueue_next(void);
|
|
|
|
|
|
|
|
/* speaks one or more IDs (from an array)). */
|
2008-09-29 16:29:51 +00:00
|
|
|
int talk_idarray(const long *idarray, bool enqueue);
|
2007-08-06 13:08:36 +00:00
|
|
|
/* This makes an initializer for the array of IDs and takes care to
|
|
|
|
put the final sentinel element at the end. */
|
|
|
|
#define TALK_IDARRAY(ids...) ((long[]){ids,TALK_FINAL_ID})
|
|
|
|
/* And this handy macro makes it look like a variadic function. */
|
|
|
|
#define talk_ids(enqueue, ids...) talk_idarray(TALK_IDARRAY(ids), enqueue)
|
|
|
|
/* This version talks only if talking menus are enabled, and does not
|
|
|
|
enqueue the initial id. */
|
|
|
|
#define cond_talk_ids(ids...) do { \
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu) \
|
2007-08-06 13:08:36 +00:00
|
|
|
talk_ids(false, ids); \
|
|
|
|
} while(0)
|
|
|
|
/* And a version that takes the array parameter... */
|
|
|
|
#define cond_talk_idarray(idarray) do { \
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu \
|
2007-08-06 13:08:36 +00:00
|
|
|
talk_idarray(idarray, false); \
|
|
|
|
} while(0)
|
|
|
|
/* Convenience macro to conditionally speak something and not have
|
|
|
|
it interrupted. */
|
|
|
|
#define cond_talk_ids_fq(ids...) do { \
|
2007-10-19 15:31:42 +00:00
|
|
|
if (global_settings.talk_menu) { \
|
2007-08-06 13:08:36 +00:00
|
|
|
talk_ids(false, ids); \
|
|
|
|
talk_force_enqueue_next(); \
|
|
|
|
} \
|
|
|
|
}while(0)
|
2007-11-07 09:28:07 +00:00
|
|
|
|
2013-07-02 06:24:00 +00:00
|
|
|
struct talk_debug_data {
|
|
|
|
char voicefile[32];
|
|
|
|
long memory_allocated, memory_used;
|
|
|
|
int num_clips, num_empty_clips;
|
|
|
|
int min_clipsize, avg_clipsize, max_clipsize;
|
|
|
|
int cached_clips;
|
|
|
|
int cache_hits;
|
|
|
|
int cache_misses;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool talk_get_debug_data(struct talk_debug_data *data);
|
|
|
|
|
2004-03-14 21:33:53 +00:00
|
|
|
#endif /* __TALK_H__ */
|