Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot decode opus that came from openAI (Data corrupted) #149

Open
MatthD opened this issue Dec 11, 2023 · 1 comment
Open

Cannot decode opus that came from openAI (Data corrupted) #149

MatthD opened this issue Dec 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@MatthD
Copy link

MatthD commented Dec 11, 2023

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
    Capture d’écran 2023-12-11 à 16 38 08

  • 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:

@MatthD MatthD added the bug Something isn't working label Dec 11, 2023
@Qjuh
Copy link

Qjuh commented Dec 11, 2023

Are you sure the opus from OpenAI is encoded as 24000 bitrate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants