@@ -12,7 +12,7 @@ import { readFileSync, writeFileSync } from 'fs';
1212export default defineCommand ( {
1313 name : 'speech synthesize' ,
1414 description : 'Synchronous TTS, up to 10k chars (speech-2.8-hd / 2.6 / 02)' ,
15- usage : 'minimax speech synthesize --text <text> --out <path> [flags]' ,
15+ usage : 'minimax speech synthesize --text <text> [ --out <path>] [flags]' ,
1616 options : [
1717 { flag : '--model <model>' , description : 'Model ID (default: speech-2.8-hd)' } ,
1818 { flag : '--text <text>' , description : 'Text to synthesize' } ,
@@ -29,14 +29,13 @@ export default defineCommand({
2929 { flag : '--subtitles' , description : 'Include subtitle timing data' } ,
3030 { flag : '--pronunciation <from/to>' , description : 'Custom pronunciation (repeatable)' } ,
3131 { flag : '--sound-effect <effect>' , description : 'Add sound effect' } ,
32- { flag : '--out <path>' , description : 'Output file path' } ,
33- { flag : '--out-format <fmt>' , description : 'Output format: hex (default), url' } ,
32+ { flag : '--out <path>' , description : 'Save audio to file (uses hex decoding)' } ,
3433 { flag : '--stream' , description : 'Stream raw audio to stdout' } ,
3534 ] ,
3635 examples : [
36+ 'minimax speech synthesize --text "Hello, world!"' ,
3737 'minimax speech synthesize --text "Hello, world!" --out hello.mp3' ,
3838 'echo "Breaking news." | minimax speech synthesize --text-file - --out news.mp3' ,
39- 'minimax speech synthesize --text "Link" --out-format url --output json' ,
4039 'minimax speech synthesize --text "Stream" --stream | mpv --no-terminal -' ,
4140 ] ,
4241 async run ( config : Config , flags : GlobalFlags ) {
@@ -59,7 +58,8 @@ export default defineCommand({
5958
6059 const model = ( flags . model as string ) || 'speech-2.8-hd' ;
6160 const voice = ( flags . voice as string ) || 'English_expressive_narrator' ;
62- const outFormat = ( flags . outFormat as string ) || 'hex' ;
61+ const outPath = flags . out as string | undefined ;
62+ const outFormat = outPath ? 'hex' : 'url' ;
6363 const format = detectOutputFormat ( config . output ) ;
6464
6565 const body : SpeechRequest = {
@@ -77,7 +77,7 @@ export default defineCommand({
7777 bitrate : ( flags . bitrate as number ) || 128000 ,
7878 channel : ( flags . channels as number ) || 1 ,
7979 } ,
80- output_format : outFormat as 'url' | 'hex' ,
80+ output_format : outFormat ,
8181 stream : flags . stream === true ,
8282 } ;
8383
@@ -117,41 +117,30 @@ export default defineCommand({
117117 body,
118118 } ) ;
119119
120- if ( outFormat === 'url' && response . data . audio_url ) {
120+ if ( outPath && response . data . audio ) {
121+ // --out given: decode hex and save to file
122+ const audioBuffer = Buffer . from ( response . data . audio , 'hex' ) ;
123+ writeFileSync ( outPath , audioBuffer ) ;
124+
121125 if ( config . quiet ) {
122- console . log ( response . data . audio_url ) ;
126+ console . log ( outPath ) ;
123127 } else {
124128 console . log ( formatOutput ( {
125- url : response . data . audio_url ,
129+ saved : outPath ,
126130 duration_ms : response . extra_info ?. audio_length ,
127131 size_bytes : response . extra_info ?. audio_size ,
132+ sample_rate : response . extra_info ?. audio_sample_rate ,
128133 } , format ) ) ;
129134 }
130- return ;
131- }
132-
133- // Hex format — decode and write to file
134- const outPath = flags . out as string ;
135- if ( ! outPath && ! config . quiet ) {
136- throw new CLIError (
137- '--out is required when using hex output format.' ,
138- ExitCode . USAGE ,
139- 'minimax speech synthesize --text "Hello" --out hello.mp3' ,
140- ) ;
141- }
142-
143- if ( response . data . audio && outPath ) {
144- const audioBuffer = Buffer . from ( response . data . audio , 'hex' ) ;
145- writeFileSync ( outPath , audioBuffer ) ;
146-
135+ } else if ( response . data . audio_url ) {
136+ // No --out: return URL
147137 if ( config . quiet ) {
148- console . log ( outPath ) ;
138+ console . log ( response . data . audio_url ) ;
149139 } else {
150140 console . log ( formatOutput ( {
151- saved : outPath ,
141+ url : response . data . audio_url ,
152142 duration_ms : response . extra_info ?. audio_length ,
153143 size_bytes : response . extra_info ?. audio_size ,
154- sample_rate : response . extra_info ?. audio_sample_rate ,
155144 } , format ) ) ;
156145 }
157146 }
0 commit comments