@@ -118,7 +118,7 @@ static mp_obj_t make_speech_iter(void) {
118118 return result ;
119119}
120120
121- static mp_obj_t pronounce (mp_obj_t words ) {
121+ static mp_obj_t translate (mp_obj_t words ) {
122122 mp_uint_t len , outlen ;
123123 const char * txt = mp_obj_str_get_data (words , & len );
124124 // Reciter truncates *output* at about 120 characters.
@@ -145,11 +145,11 @@ static mp_obj_t pronounce(mp_obj_t words) {
145145 // Prevent input becoming invisible to GC due to tail-call optimisation.
146146 MP_STATE_PORT (speech_data ) = NULL ;
147147 return res ;
148- }MP_DEFINE_CONST_FUN_OBJ_1 (pronounce_obj , pronounce );
148+ }MP_DEFINE_CONST_FUN_OBJ_1 (translate_obj , translate );
149149
150150extern int debug ;
151151
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 ) {
153153
154154 static const mp_arg_t allowed_args [] = {
155155 { 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
161161
162162 // parse args
163163 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 );
165165
166166 sam_memory * sam = m_new (sam_memory , 1 );
167167 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
175175 debug = args [4 ].u_bool ;
176176
177177 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 );
179179 buf_start_pos = 0 ;
180180 speech_iterator_t * src = make_speech_iter ();
181181 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
203203}
204204
205205static 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);
207208}
208209MP_DEFINE_CONST_FUN_OBJ_KW (say_obj , 1 , say );
209210
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+
210216static 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);
212218}
213219MP_DEFINE_CONST_FUN_OBJ_KW (sing_obj , 1 , sing );
214220
@@ -217,6 +223,7 @@ static const mp_map_elem_t _globals_table[] = {
217223 { MP_OBJ_NEW_QSTR (MP_QSTR_say ), (mp_obj_t )& say_obj },
218224 { MP_OBJ_NEW_QSTR (MP_QSTR_sing ), (mp_obj_t )& sing_obj },
219225 { 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 },
220227};
221228static MP_DEFINE_CONST_DICT (_globals , _globals_table ) ;
222229
0 commit comments