@@ -118,7 +118,7 @@ static mp_obj_t make_speech_iter(void) {
118
118
return result ;
119
119
}
120
120
121
- static mp_obj_t pronounce (mp_obj_t words ) {
121
+ static mp_obj_t translate (mp_obj_t words ) {
122
122
mp_uint_t len , outlen ;
123
123
const char * txt = mp_obj_str_get_data (words , & len );
124
124
// Reciter truncates *output* at about 120 characters.
@@ -145,11 +145,11 @@ static mp_obj_t pronounce(mp_obj_t words) {
145
145
// Prevent input becoming invisible to GC due to tail-call optimisation.
146
146
MP_STATE_PORT (speech_data ) = NULL ;
147
147
return res ;
148
- }MP_DEFINE_CONST_FUN_OBJ_1 (pronounce_obj , pronounce );
148
+ }MP_DEFINE_CONST_FUN_OBJ_1 (translate_obj , translate );
149
149
150
150
extern int debug ;
151
151
152
- static mp_obj_t articulate (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args , bool sing ) {
152
+ static mp_obj_t articulate (mp_obj_t phonemes , mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args , bool sing ) {
153
153
154
154
static const mp_arg_t allowed_args [] = {
155
155
{ MP_QSTR_pitch , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = DEFAULT_PITCH } },
@@ -161,7 +161,7 @@ static mp_obj_t articulate(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
161
161
162
162
// parse args
163
163
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
164
- mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
164
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
165
165
166
166
sam_memory * sam = m_new (sam_memory , 1 );
167
167
MP_STATE_PORT (speech_data ) = sam ;
@@ -175,7 +175,7 @@ static mp_obj_t articulate(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
175
175
debug = args [4 ].u_bool ;
176
176
177
177
mp_uint_t len ;
178
- const char * input = mp_obj_str_get_data (pos_args [ 0 ] , & len );
178
+ const char * input = mp_obj_str_get_data (phonemes , & len );
179
179
buf_start_pos = 0 ;
180
180
speech_iterator_t * src = make_speech_iter ();
181
181
buf = src -> buf ;
@@ -203,12 +203,18 @@ static mp_obj_t articulate(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t
203
203
}
204
204
205
205
static mp_obj_t say (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
206
- return articulate (n_args , pos_args , kw_args , false);
206
+ mp_obj_t phonemes = translate (pos_args [0 ]);
207
+ return articulate (phonemes , n_args - 1 , pos_args + 1 , kw_args , false);
207
208
}
208
209
MP_DEFINE_CONST_FUN_OBJ_KW (say_obj , 1 , say );
209
210
211
+ static mp_obj_t pronounce (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
212
+ return articulate (pos_args [0 ], n_args - 1 , pos_args + 1 , kw_args , false);
213
+ }
214
+ MP_DEFINE_CONST_FUN_OBJ_KW (pronounce_obj , 1 , pronounce );
215
+
210
216
static mp_obj_t sing (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
211
- return articulate (n_args , pos_args , kw_args , true);
217
+ return articulate (pos_args [ 0 ], n_args - 1 , pos_args + 1 , kw_args , true);
212
218
}
213
219
MP_DEFINE_CONST_FUN_OBJ_KW (sing_obj , 1 , sing );
214
220
@@ -217,6 +223,7 @@ static const mp_map_elem_t _globals_table[] = {
217
223
{ MP_OBJ_NEW_QSTR (MP_QSTR_say ), (mp_obj_t )& say_obj },
218
224
{ MP_OBJ_NEW_QSTR (MP_QSTR_sing ), (mp_obj_t )& sing_obj },
219
225
{ MP_OBJ_NEW_QSTR (MP_QSTR_pronounce ), (mp_obj_t )& pronounce_obj },
226
+ { MP_OBJ_NEW_QSTR (MP_QSTR_translate ), (mp_obj_t )& translate_obj },
220
227
};
221
228
static MP_DEFINE_CONST_DICT (_globals , _globals_table ) ;
222
229
0 commit comments