diff --git a/cmd/speak.go b/cmd/speak.go index e043407..00c8682 100644 --- a/cmd/speak.go +++ b/cmd/speak.go @@ -535,6 +535,8 @@ func inferFormatFromExt(path string) string { return "mp3_44100_128" case ".wav", ".wave": return "pcm_44100" + case ".ogg", ".opus": + return "opus_48000_64" default: return "" } diff --git a/internal/elevenlabs/client.go b/internal/elevenlabs/client.go index b8524d5..6143749 100644 --- a/internal/elevenlabs/client.go +++ b/internal/elevenlabs/client.go @@ -213,11 +213,15 @@ func (c *Client) StreamTTS(ctx context.Context, voiceID string, payload TTSReque return nil, err } u.Path = path.Join(u.Path, "/v1/text-to-speech", voiceID, "stream") + q := u.Query() if latency > 0 { - q := u.Query() q.Set("optimize_streaming_latency", fmt.Sprint(latency)) - u.RawQuery = q.Encode() } + if payload.OutputFormat != "" { + q.Set("output_format", payload.OutputFormat) + payload.OutputFormat = "" // don't send in body + } + u.RawQuery = q.Encode() bodyBytes, err := json.Marshal(payload) if err != nil { @@ -229,7 +233,7 @@ func (c *Client) StreamTTS(ctx context.Context, voiceID string, payload TTSReque return nil, err } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "audio/mpeg") + req.Header.Set("Accept", "*/*") req.Header.Set("xi-api-key", c.apiKey) resp, err := c.httpClient.Do(req) @@ -253,6 +257,12 @@ func (c *Client) ConvertTTS(ctx context.Context, voiceID string, payload TTSRequ return nil, err } u.Path = path.Join(u.Path, "/v1/text-to-speech", voiceID) + q := u.Query() + if payload.OutputFormat != "" { + q.Set("output_format", payload.OutputFormat) + payload.OutputFormat = "" + } + u.RawQuery = q.Encode() bodyBytes, err := json.Marshal(payload) if err != nil { @@ -264,7 +274,7 @@ func (c *Client) ConvertTTS(ctx context.Context, voiceID string, payload TTSRequ return nil, err } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "audio/mpeg") + req.Header.Set("Accept", "*/*") req.Header.Set("xi-api-key", c.apiKey) resp, err := c.httpClient.Do(req)