Trying to convert wav to mp3

Trying to convert .wav file into mp3, Can anyone help with dialplan code

same => n,MixMonitor({CALLFILENAME}.wav) same =>n,System(/usr/bin/sox {CALLFILENAME}.wav -c1 -r 8000 ${CALLFILENAME}.mp3)

  1. Please use 'Preformatted text' tags on snippets. What you’ve posted will not execute.

  2. Does the ‘sox’ command yield any clues when executed from a console shell? Depending on how it is compiled, sox may not contain MP3 code. Personally, I use ‘lame’ for encoding to MP3.

  3. Does bumping up ‘verbose’ and ‘debug’ in the Asterisk shell yield any clues?

does this variable have the full file path built in ?

yes ambiorixg.
@ sedwards I tried to lame too below is the code. I can convert it successfully however its not working with right ear & left ear recording.
same =>n,MixMonitor({CALLFILENAME}.wav,W(1),lame -V3 {CALLFILENAME}.wav ${CALLFILENAME}.mp3)

Please use </> in the icon bar, <CTRL>+<SHIFT>+C, or type ` (AKA backtick) for sub-line snippets before and after the snippet or backtick+backtick+backtick on a line of it’s own before and after a multi-line snippet.

I don’t understand this.

I need in and out both files in call recording I tried in below way however unable to convert both the files in mp3

same => n,MixMonitor(mixed.wav,r({CALLFILENAME}-in.wav)t({CALLFILENAME}-out.wav),lame -V3 *{CALLFILENAME}.wav {CALLFILENAME}.mp3)

Please, please, please. You’re making this harder that it should be.

When you post a multi-line snippet (or a single full line), please add a line consisting of 3 backticks before the snippet and a line consisting of 3 backticks after the snippet.

I feel like I’m shooting at a moving target :slight_smile: You’re introducing new requirements.

Now it sounds like you want to record the receive audio in a file, the transmit audio in a separate file, mix them into a stereo WAV file and then encode the WAV into MP3?

This should record the audio into 2 separate files. How are you passing these 2 new file names to lame? The answer is you are not. Lame is still looking for ${CALLFILENAME}.wav. (Note I used preformatted text tags so the forum software didn’t eat my dollar sign).

I suggest you change the ‘command’ argument to be a shell script and just pass ${CALLFILENAME}.

In the script, you can use sox to mix the 2 monaural files into a single stereo file and then use lame to convert to MP3.

Yes Sedwards, sorry I did not explain in proper way.
Yes I need to record both audio in separate file however I am not bother about merging these two files on asterisk only, I am ok if in & out both recording in separate files.

But I need both audio file in mp3. somehow I have done and sharing you the code please check once whether is it manageable code or not but its working.

same => n,MixMonitor(mixed.wav,r({CALLFILENAME}-in.wav),lame -V3 {CALLFILENAME}-in.wav {CALLFILENAME}-in.mp3) same => n,MixMonitor(mixed.wav,t({CALLFILENAME}-out.wav),lame -V3 {CALLFILENAME}-out.wav {CALLFILENAME}-out.mp3)

${CALLFILENAME} is having complete path of audio files

Please repost with correct formatting.

Ok now the requirement is bit changed we dont need converted mp3

  1. We need originally asterisk creates 16000 Hz .wav file
  2. We need originally asterisk creates 16000 Hz .mp3 files

Done need any conversion through sox,lame etc

I don’t believe such a thing exists, even ignoring the 16000 Hz part. Asterisk has no codec or format modules for mp3.

mp3 files are not parameterized by sampling rate. I think the original, time domain, sampling is 44100 Hz.

Why do you need MP3? It is over-specified for telephony, expensive, in processing power to generate, and, I believe, even Apple devices support some formats that Asterisk directly supports.

Going with Mp3 is the only reason to save space consumption as wav takes 1 mb space for 1 minute recording where Mp3 takes just half.

But the most important is by default .wav files are getting generated with sample rate 8000 can I make any changes in config after and asterisk by default create recording with 16000 or higher sample rate’s recording

If calls involved the PSTN, there is no point in exceeding 8kHz sampling.

Asterisk will only generate RIFF wrappers for 16 bit signed 8kHz and GSM standard rate codecs (.wav and .WAV, respectively). For 16 bit signed linear at 16kHz, youj would need to, externally, convert .sln16 to an RIFF file.

1 milli-bit per minute is very good :slightly_smiling_face:

is it possible over VOIP calling?

End to end VoIP can use codecs that are better than 3.1kHz audio, but if you go through a service provider, they will likely have the PSTN somewhere in the path, which, at best, is 64kb/s, but in places may be only 3.1kHz audio, or even, like typical mobile networks, 3.1kHz voice.

The 64 or 56 kb/s only applies to native ISDN devices, at both ends.

3.1kHz isn’t the sampling rate; it is the bandwidth, nominally 300Hz - 3,400Hz.


Maybe whomever is setting requirements should state what they are trying to achieve. You keep moving the goalpost with fluid and conflicting requirements. If saving space is important, why is doubling the sample rate important.

Maybe a clear statement of what you are doing would yield a clue as to what needs to be done.

@Sedwards I am sorry for making it tough however changing requirement was the situation’s demand anyways David has opened everything and case is solved now.

I found the similar thought like David from other sources too. That while using PSTN/GSM line for calling we can make more than 8khz sample rate the only way is conversion.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.