@@ -1733,6 +1733,7 @@ final class TalkModeManager: NSObject {
17331733 if let outputFormat = self . defaultOutputFormat, !outputFormat. isEmpty {
17341734 payload [ " outputFormat " ] = outputFormat
17351735 }
1736+ if !language. isEmpty { payload [ " language " ] = language }
17361737 let jsonData = try JSONSerialization . data ( withJSONObject: payload)
17371738 let json = String ( data: jsonData, encoding: . utf8)
17381739
@@ -1749,13 +1750,20 @@ final class TalkModeManager: NSObject {
17491750 userInfo: [ NSLocalizedDescriptionKey: " gateway talk.speak returned empty audio " ] )
17501751 }
17511752
1752- // Play returned audio as stream via MP3 player (most providers return MP3)
1753+ // Play returned audio in the format returned by the provider
17531754 let stream = AsyncThrowingStream < Data , Error > { continuation in
17541755 continuation. yield ( audioData)
17551756 continuation. finish ( )
17561757 }
1757- self . lastPlaybackWasPCM = false
1758- let playback = await self . mp3Player. play ( stream: stream)
1758+ let sampleRate = result. outputformat. flatMap { TalkTTSValidation . pcmSampleRate ( from: $0) }
1759+ let playback : StreamingPlaybackResult
1760+ if let sampleRate {
1761+ self . lastPlaybackWasPCM = true
1762+ playback = await self . pcmPlayer. play ( stream: stream, sampleRate: sampleRate)
1763+ } else {
1764+ self . lastPlaybackWasPCM = false
1765+ playback = await self . mp3Player. play ( stream: stream)
1766+ }
17591767 if !playback. finished, playback. interruptedAt == nil {
17601768 throw NSError (
17611769 domain: " TalkModeManager " ,
@@ -2266,9 +2274,20 @@ final class TalkModeManager: NSObject {
22662274 }
22672275
22682276 guard context. canUseElevenLabs, let apiKey = context. apiKey, let voiceId = context. voiceId else {
2269- try ? await TalkSystemSpeechSynthesizer . shared. speak (
2270- text: text,
2271- language: self . incrementalSpeechLanguage)
2277+ // FIX #98153: Route incremental playback through Gateway TTS for non-ElevenLabs providers
2278+ if self . activeTalkProvider != Self . defaultTalkProvider {
2279+ let resolvedVoice = self . currentVoiceId ?? self . defaultVoiceId
2280+ try ? await self . playGatewayTalkSpeak (
2281+ text: text,
2282+ directive: self . incrementalSpeechDirective,
2283+ voiceId: resolvedVoice,
2284+ modelId: self . currentModelId ?? self . defaultModelId,
2285+ language: self . incrementalSpeechLanguage)
2286+ } else {
2287+ try ? await TalkSystemSpeechSynthesizer . shared. speak (
2288+ text: text,
2289+ language: self . incrementalSpeechLanguage)
2290+ }
22722291 return
22732292 }
22742293
0 commit comments