Skip to main content
Denoise a WAV file and save the result to a new WAV file.

Prerequisites

  • A Telnyx API key.
  • A mono 16-bit PCM WAV file with a sample rate from 8 kHz to 48 kHz. To convert a file with ffmpeg:
For telephony audio, use -ar 8000. Do not upsample 8 kHz audio to a higher rate.

How the examples work

  1. Read the sample rate from the WAV header.
  2. Connect with format=l16, the same sample_rate, and channels=1.
  3. Send the audio in 20 ms binary chunks, then send {"type": "end_of_stream"}.
  4. Read messages until the server closes the connection. Keep the binary frames and print JSON errors.
  5. On close 1000, write the denoised audio to denoised.wav.
  6. On close 1001, 1011, or 1013, or HTTP 503, the failure is temporary. Wait, then send the file again on a new connection, with exponential backoff. Any other close is an error.
The examples send the whole file in one session, so they suit files shorter than 590 seconds. A longer file reaches the session limit and closes with 1008. Split longer audio into parts and send each part in its own session. See End of stream for why the examples send end_of_stream instead of only closing the connection.

Code

Real-time streams

For live audio, such as a microphone or a media stream, send each chunk as soon as you capture it and play or forward each binary response as soon as it arrives. Keep chunks small (10–40 ms) for low latency. When the stream ends, send {"type": "end_of_stream"} and keep reading until the server closes the connection. Sessions are limited to 590 seconds. At the limit, the server returns the remaining audio and closes with 1008 and a max_session_duration error. Reconnect to continue. See Session duration.