pipecat-ai / pipecat

Open Source framework for voice and multimodal conversational AI
BSD 2-Clause "Simplified" License
3.44k stars 335 forks source link

exotel example with jittery audio #747

Open ajay-ranga opened 3 days ago

ajay-ranga commented 3 days ago

Please describe the changes in your PR. If it is addressing an issue, please reference that as well.

ajay-ranga commented 3 days ago
async convertToExotelWavFormat(inputBuffer) {
    const tmpDir = os.tmpdir();
    const inputFile = path.join(tmpDir, `input${Date.now()}.pcm`);
    const outputFile = path.join(tmpDir, `output_${Date.now()}.wav`);

    try {
      await fs.writeFile(inputFile, inputBuffer);
      await new Promise((resolve, reject) => {
        const command = `ffmpeg -y -f s16le -ar 16000 -ac 1 -i "${inputFile}" -ar 8000 -ac 1 -sample_fmt s16 "${outputFile}"`;
        exec(command, (error, stdout, stderr) => {
          if (error) {
            console.error('Error in audio conversion with ffmpeg:', stderr);
            reject(error);
          } else {
            resolve();
          }
        });
      });

      return outputFile;
    } catch (err) {
      console.error('Error in audio file handling:', err);
      throw err;
    } finally {
      try {
        await fs.unlink(inputFile);
      } catch (cleanupErr) {
        console.error('Error cleaning up temporary PCM file:', cleanupErr);
      }
    }
  }
}

exotel provides us this method to get the audio working in desired format.

jonnyjohnson1 commented 4 hours ago

What did the "jittery audio" sound like? I'm getting some weird staticky noise coming back from eleven labs over a websocket connection with the pcm_16000 setting.

Is that what you had to fix with this pull request in Exotel?