@@ -3,12 +3,12 @@ import { CLIError } from '../../errors/base';
33import { ExitCode } from '../../errors/codes' ;
44import { request , requestJson } from '../../client/http' ;
55import { speechEndpoint } from '../../client/endpoints' ;
6- import { parseSSE } from '../../client/stream' ;
76import { detectOutputFormat , formatOutput , dryRun } from '../../output/formatter' ;
87import { saveAudioOutput } from '../../output/audio' ;
98import { writeFileSync } from 'fs' ;
109import { readTextFromPathOrStdin } from '../../utils/fs' ;
1110import { T2A_FORMATS , formatList , validateAudioFormat , validateT2AStreaming , t2aDefaultSampleRate } from '../../utils/audio-formats' ;
11+ import { pipeAudioStream } from '../../utils/audio-stream' ;
1212import type { Config } from '../../config/schema' ;
1313import type { GlobalFlags } from '../../types/flags' ;
1414import type { SpeechRequest , SpeechResponse } from '../../types/api' ;
@@ -105,14 +105,7 @@ export default defineCommand({
105105
106106 if ( flags . stream ) {
107107 const res = await request ( config , { url, method : 'POST' , body, stream : true } ) ;
108- for await ( const event of parseSSE ( res ) ) {
109- if ( ! event . data || event . data === '[DONE]' ) break ;
110- const parsed = JSON . parse ( event . data ) ;
111- const audioHex = parsed ?. data ?. audio ;
112- if ( audioHex ) {
113- process . stdout . write ( Buffer . from ( audioHex , 'hex' ) ) ;
114- }
115- }
108+ await pipeAudioStream ( res ) ;
116109 return ;
117110 }
118111
0 commit comments