Skip to content

Commit ed54f34

Browse files
committed
Speech: add pitch,sing,mouth,throat parameters; Factor out reciter to be self contained and use dynamically allocated memory.
1 parent 761547e commit ed54f34

File tree

9 files changed

+165
-87
lines changed

9 files changed

+165
-87
lines changed

inc/genhdr/qstrdefs.generated.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,11 @@ QDEF(MP_QSTR_size, (const byte*)"\x20\x04" "size")
698698
QDEF(MP_QSTR_is_playing, (const byte*)"\x04\x0a" "is_playing")
699699
QDEF(MP_QSTR_speech, (const byte*)"\x6d\x06" "speech")
700700
QDEF(MP_QSTR_say, (const byte*)"\xae\x03" "say")
701+
QDEF(MP_QSTR_pronounce, (const byte*)"\x94\x09" "pronounce")
702+
QDEF(MP_QSTR_sing, (const byte*)"\xb6\x04" "sing")
703+
QDEF(MP_QSTR_throat, (const byte*)"\x31\x06" "throat")
704+
QDEF(MP_QSTR_mouth, (const byte*)"\x6e\x05" "mouth")
705+
QDEF(MP_QSTR_speed, (const byte*)"\x62\x05" "speed")
701706
QDEF(MP_QSTR_radio, (const byte*)"\xd4\x05" "radio")
702707
QDEF(MP_QSTR_config, (const byte*)"\x4f\x06" "config")
703708
QDEF(MP_QSTR_send_bytes, (const byte*)"\xbf\x0a" "send_bytes")

inc/microbit/mpconfigport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ extern const struct _mp_obj_module_t speech_module;
125125
uint8_t *radio_buf; \
126126
void *pwm_next_event; \
127127
void *audio_buffer; \
128-
void *audio_source;
128+
void *audio_source; \
129+
void *speech_data;
129130

130131
// We need to provide a declaration/definition of alloca()
131132
#include <alloca.h>

inc/microbit/qstrdefsport.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,12 @@ Q(is_playing)
422422

423423
Q(speech)
424424
Q(say)
425-
425+
Q(pronounce)
426+
Q(sing)
427+
Q(pitch)
428+
Q(throat)
429+
Q(mouth)
430+
Q(speed)
426431
Q(radio)
427432
Q(reset)
428433
Q(config)

source/lib/sam/main.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ int sam_main(int argc, char **argv)
6060
int i;
6161
int phonetic = 0;
6262

63-
char input[256];
63+
reciter_memory rec_mem;
6464

65-
for(i=0; i<256; i++) input[i] = 0;
65+
for(i=0; i<256; i++) rec_mem.input[i] = 0;
6666

6767
if (argc <= 1)
6868
{
@@ -75,8 +75,8 @@ int sam_main(int argc, char **argv)
7575
{
7676
if (argv[i][0] != '-')
7777
{
78-
strncat(input, argv[i], 256);
79-
strncat(input, " ", 256);
78+
strncat(rec_mem.input, argv[i], 256);
79+
strncat(rec_mem.input, " ", 256);
8080
} else
8181
{
8282
if (strcmp(&argv[i][1], "sing")==0)
@@ -120,24 +120,24 @@ int sam_main(int argc, char **argv)
120120
i++;
121121
} //while
122122

123-
for(i=0; input[i] != 0; i++)
124-
input[i] = toupper((int)input[i]);
123+
for(i=0; rec_mem.input[i] != 0; i++)
124+
rec_mem.input[i] = toupper((int)rec_mem.input[i]);
125125

126126
if (debug)
127127
{
128-
if (phonetic) printf("phonetic input: %s\n", input);
129-
else printf("text input: %s\n", input);
128+
if (phonetic) printf("phonetic input: %s\n", rec_mem.input);
129+
else printf("text input: %s\n", rec_mem.input);
130130
}
131131

132132
if (!phonetic)
133133
{
134-
strncat(input, "[", 256);
135-
if (!TextToPhonemes(input)) return 1;
134+
strncat(rec_mem.input, "[", 256);
135+
if (!TextToPhonemes(&rec_mem)) return 1;
136136
if (debug)
137-
printf("phonetic input: %s\n", input);
138-
} else strncat(input, "\x9b", 256);
137+
printf("phonetic input: %s\n", rec_mem.input);
138+
} else strncat(rec_mem.input, "\x9b", 256);
139139

140-
SetInput(input);
140+
SetInput(rec_mem.input, strlen(rec_mem.input));
141141
if (!SAMMain())
142142
{
143143
PrintUsage();

0 commit comments

Comments
 (0)