@@ -26,6 +26,7 @@ import {
2626} from "./tts.js" ;
2727
2828const XAI_SPEECH_RESPONSE_FORMATS = [ "mp3" , "wav" , "pcm" , "mulaw" , "alaw" ] as const ;
29+ const DEFAULT_GENERATED_AUDIO_MAX_BYTES = 16 * 1024 * 1024 ;
2930
3031type XaiSpeechResponseFormat = ( typeof XAI_SPEECH_RESPONSE_FORMATS ) [ number ] ;
3132
@@ -130,6 +131,16 @@ function readXaiOverrides(overrides: SpeechProviderOverrides | undefined): XaiTt
130131 } ;
131132}
132133
134+ function resolveGeneratedAudioMaxBytes ( req : {
135+ cfg : { agents ?: { defaults ?: { mediaMaxMb ?: number } } } ;
136+ } ) : number {
137+ const configured = req . cfg . agents ?. defaults ?. mediaMaxMb ;
138+ if ( typeof configured === "number" && Number . isFinite ( configured ) && configured > 0 ) {
139+ return Math . floor ( configured * 1024 * 1024 ) ;
140+ }
141+ return DEFAULT_GENERATED_AUDIO_MAX_BYTES ;
142+ }
143+
133144function parseDirectiveToken ( ctx : SpeechDirectiveTokenParseContext ) : {
134145 handled : boolean ;
135146 overrides ?: SpeechProviderOverrides ;
@@ -231,6 +242,7 @@ export function buildXaiSpeechProvider(): SpeechProviderPlugin {
231242 speed : overrides . speed ?? config . speed ,
232243 responseFormat,
233244 timeoutMs : req . timeoutMs ,
245+ maxBytes : resolveGeneratedAudioMaxBytes ( req ) ,
234246 } ) ;
235247 return {
236248 audioBuffer,
@@ -254,6 +266,7 @@ export function buildXaiSpeechProvider(): SpeechProviderPlugin {
254266 speed : overrides . speed ?? config . speed ,
255267 responseFormat : outputFormat ,
256268 timeoutMs : req . timeoutMs ,
269+ maxBytes : resolveGeneratedAudioMaxBytes ( req ) ,
257270 } ) ;
258271 return { audioBuffer, outputFormat, sampleRate } ;
259272 } ,
0 commit comments