Skip to content

Instantly share code, notes, and snippets.

@fians
Created February 3, 2018 11:50
Show Gist options
  • Save fians/18b4c7a8d47a7a7648766946cdfd1050 to your computer and use it in GitHub Desktop.
Save fians/18b4c7a8d47a7a7648766946cdfd1050 to your computer and use it in GitHub Desktop.
Use FFMPEG to convert WAV files to MP3 for Nexmo Stream Audio

Use FFMPEG to convert WAV files to MP3 for Nexmo Stream Audio

Nexmo allow us to setup Stream NCCO object to stream a speech sound to the call receiver. Here is some specification of the allowed sound format for stream url:

MP3:

  • MPEG Audio Layer 3, version 2
  • Constant bit rate
  • Bit rate: 16 Kbps (8, 32, 64 also supported)
  • Sampling rate: 16.0 KHz
  • 1 channel
  • Lossy compression
  • Stream size: 10.1 KiB (91%)
  • Encoded with LAME 3.99.5

WAV:

  • 8 or 16-bit Linear PCM
  • G.711 A-law/u-law
  • Microsoft GSM

But sometimes the WAV files is bigger and make Nexmo takes time to load the sound file before start playing on the call. We can use FFMPEG to convert WAV files to MP3 that suitable. First download FFMPEG executable here. Then run this command:

ffmpeg -i /path/to/source.wav -vn -ar 16000 -ac 1 -ab 64k -f mp3 /path/to/target.mp3

The default bitrate on command above is 64K which passed on -ab parameter. You can change the bitrate to 32K or 16K. The smaller bitrate you choose, the smaller it output size, but also it will affect the quality of the mp3 sound output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment