Open MatthD opened 7 months ago
Please describe the problem you are having in as much detail as possible:
Trying to decode opus data that come from open-ai tts
Include a reproducible code sample here, if possible:
import fs from "fs"; import path from "path"; import "openai/shims/node"; import OpenAI from "openai"; import { OpusEncoder } from "@discordjs/opus"; const openai = new OpenAI({ apiKey: "***" // replace this with open-ai key, }); const speechFile = path.resolve("./speech.ogg"); const speechFilePCM = path.resolve("./speech.pcm"); async function main() { const opusEncoder = new OpusEncoder(24000, 1); const opus = await openai.audio.speech.create({ response_format: "opus", model: "tts-1", voice: "alloy", input: Hello I am a human trying to speech my voice", }); const buffer = Buffer.from(await opus.arrayBuffer()); const decoded = await fs.promises.writeFile(speechFile, buffer); const testDecodedPCM = opusEncoder.decode(buffer); // FAIL HERE // const decodedPCM = await fs.promises.writeFile(speechFilePCM, testDecodedPCM); } main();
Further details:
@discordjs/opus version: 0.9.0
Node.js version: 16.20.1
Operating system: Mac os 14.1.2
Priority this issue should have – please be realistic and elaborate if possible:
Are you sure the opus from OpenAI is encoded as 24000 bitrate?
Please describe the problem you are having in as much detail as possible:
Trying to decode opus data that come from open-ai tts
Include a reproducible code sample here, if possible:
Further details:
@discordjs/opus version: 0.9.0![Capture d’écran 2023-12-11 à 16 38 08](https://github.com/discordjs/opus/assets/7901366/2f51f90c-1ec6-4cb6-8a51-e16e77eb6277)
Node.js version: 16.20.1
Operating system: Mac os 14.1.2
Priority this issue should have – please be realistic and elaborate if possible: