Skip to content

Commit

Permalink
use opus for voicesynth
Browse files Browse the repository at this point in the history
  • Loading branch information
phughesmcr committed Oct 8, 2024
1 parent b60b9c2 commit c42f559
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions routes/api/voicesynth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,22 @@ export const handler: Handlers<VoiceSynthRequest | null, unknown> = {
model: DEFAULT_VOICE_MODEL,
voice: voice.toLowerCase().trim() as VoiceType,
input: props.message,
response_format: "opus",
});

if (!audioResponse) {
throw new Error("No response from speech service");
}

const contentType = audioResponse.headers.get("content-type");
const audioFormat = contentType ? contentType.split("/")[1] : "mp3";

// Return the audio data as an ArrayBuffer instead of base64
const audioBuffer = await audioResponse.arrayBuffer();

return new Response(
audioBuffer,
{
status: 200,
headers: {
"Content-Type": `audio/${audioFormat}`,
"Content-Disposition": "attachment; filename=speech.mp3",
"Content-Type": "audio/opus",
"Content-Disposition": `attachment; filename=speech.opus`,
"Cache-Control": "no-cache; no-store;",
"X-Content-Type-Options": "nosniff",
},
Expand Down

0 comments on commit c42f559

Please sign in to comment.