charactr-platform / charactr-api-sdk-ts

TypeScript/JavaScript SDK to interact with the Charactr API.
Other
3 stars 1 forks source link

Crash reproducing example tts_stream_duplex #11

Open clementbmn opened 7 months ago

clementbmn commented 7 months ago

Hi, I am trying to use your sdk and encountered this error with the code provided in examples/nodejs/tts_stream_duplex.ts

    at /Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:6691
    at new Promise (<anonymous>)
    at e.<anonymous> (/Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:6622)
    at /Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:4868
    at Object.next (/Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:4973)
    at /Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:3864
    at new Promise (<anonymous>)
    at r (/Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:3609)
    at e.convertStreamDuplex (/Users/clement/Work/IBridgePeople/gemelo/node_modules/@charactr/api-sdk/dist/sdk.es5.js:1:6542)
    at nodeTTSStreamDuplexExample (file:///Users/clement/Work/IBridgePeople/gemelo/index.js:19:32)

Node.js v18.16.1

My code :

import charactr from "@charactr/api-sdk";
import * as fs from "fs";
import { credentials } from "./credentials.js";

async function nodeTTSStreamDuplexExample() {
  const sdk = new charactr.CharactrAPISDK(credentials);

  await sdk.init();

  const fileStream = fs.createWriteStream("./result_tts_stream_duplex.wav");

  fileStream.on("error", (error) => {
    console.error(
      `An error occurred while writing to the file. Error: ${error.message}`
    );
  });

  const voices = await sdk.tts.getVoices();
  const stream = await sdk.tts.convertStreamDuplex(voices[0], {
    onData: (data) => {
      fileStream.write(data);
    },
    onClose: (event) => {
      fileStream.end();
      if (event.code === 1000) {
        console.log(
          "result_tts_stream_duplex.wav has been saved successfully."
        );
      } else {
        console.error(`error [${event.code}]: ${event.reason}`);
        console.log(
          "result_tts_stream_duplex.wav has been saved but it can be corrupted or incomplete."
        );
      }
    },
  });
  stream.convert("Hello world from the charactr TTS Duplex Streaming.");
  stream.close();
}
nodeTTSStreamDuplexExample();

I'm on OSX M2 if that can be of any influence

clementbmn commented 7 months ago

Went into this when trying to use the source code as described in the README.md, maybe it's related : error [1008]: account tier doesn't have access to this feature My client id is 9eCuB26VpVEoDYMU0ndlojxmrEBQ3Hvc