OpenGlass icon indicating copy to clipboard operation
OpenGlass copied to clipboard

browser console error

Open mcy567 opened this issue 1 year ago • 4 comments

053c59f55af9b7a527c1492a231ebd3 Error message:

Error in textToSpeech: TypeError: Cannot read properties of undefined (reading 'decodeAudioData')

Related Codes

    try {
      console.log("aaaaaaaaaaaaaa:", text);
      const response = await _axios.default.post("https://uiuiapi.com/v1/audio/speech", {
        input: text,
        // Use 'input' instead of 'text'
        voice: "nova",
        model: "tts-1"
      }, {
        headers: {
          'Authorization': `Bearer ${_keys.keys.openai}`,
          // Replace YOUR_API_KEY with your actual OpenAI API key
          'Content-Type': 'application/json'
        },
        responseType: 'arraybuffer' // This will handle the binary data correctly
      });
      console.log("bbbbbbbb", response);
      console.log("bbbbbbbb", response.data);

      // Decode the audio data asynchronously
      const audioBuffer = await audioContext.decodeAudioData(response.data);

      // Create an audio source
      const source = audioContext.createBufferSource();
      source.buffer = audioBuffer;
      source.connect(audioContext.destination);
      source.start(); // Play the audio immediately

      return response.data;
    } catch (error) {
      console.error("Error in textToSpeech:", error);
      return null; // or handle error differently
    }
  }```
I don't know where the problem is.I hope I can get some help.

mcy567 avatar May 28 '24 02:05 mcy567

ahh i have run into the same error

Yuanzan avatar May 28 '24 05:05 Yuanzan

Did you follow the readme :"Before you flash go to the "Tools" drop down in the Arduino IDE and make sure you set "PSRAM:" to be "PSRAM: "OPI PSRAM""?

silentlit avatar May 30 '24 09:05 silentlit

I confirm that I have chosen OPI PSRAM. 微信图片_20240530201550

mcy567 avatar May 30 '24 12:05 mcy567

await audioContext.decodeAudioData

在这之前增加哥判断如果audioContext没有初始化,则初始化它 if (!audioContext) { await startAudio(); }

fre2d0m avatar Jul 08 '24 16:07 fre2d0m