How to encode WAV to play with SIPp

2019-02-20 07:17发布

By looking into another SIPp related question I learned that it is now possible to play WAV files using the rtp_stream action.

I've tried several different WAV files with no success. All I get is some noise instead of the expected sound.

In one comment in the mentioned question there is a simple instruction to convert a WAV file to a compatible format but it didn't work as well.

I've also tried to use sox to convert this file with no success.

Can anyone instruct me on how to generate a valid WAV file to be used with SIPp?

This is my recv 200 OK command which includes the play audio action:

<recv response="200" rtd="true">
  <action>
    <exec rtp_stream="sorry_dave.wav,-1" />
  </action>
</recv>

标签: sip wav sipp
3条回答
在下西门庆
2楼-- · 2019-02-20 08:02

You can use Audacity to encode wav for sipp : Select in the bottom bar 8000Hz for the project and export the audio as 'Another compressed format' : click 'Options' and select 'WAV (Microsoft)' Header and 'A-Law' Encoding (for PCMA) or 'U-Law' (for PCMU).

You should also verify your scenario file : SDP message must have PCMA or PCMU audio and use "rtpstream_audio_port" like this (for PCMA) :

  m=audio [rtpstream_audio_port] RTP/AVP 8
  a=rtpmap:8 PCMA/8000
查看更多
相关推荐>>
3楼-- · 2019-02-20 08:03

Sorry - It's a bit vague now as it's been so long since I did this. To my best recollection u-law encoding didn't work in sipp so I encoded the file as a-law using this script I built. I noted there were some nuances to the conversion using sox. In my opinion you either have a mismatched SDP, or are incorrectly encoding the file, make sure you only use one channel. Try the methods and code I posted below.

The file header should read

File Size: 54.7k Bit Rate: 64.1k Encoding: A-law
Channels: 1 @ 13-bit
Samplerate: 8000Hz
Replaygain: off
Duration: 00:00:06.83

or

File Size: 54.7k Bit Rate: 64.1k Encoding: u-law
Channels: 1 @ 14-bit
Samplerate: 8000Hz
Replaygain: off
Duration: 00:00:06.83

./wav_to_gsm.sh sorry_dave.wav sorry_dave_alaw.wav sox alaw

#!/bin/bash

if [ -z "$4" ];then
   echo "usage: $0 [input.wav] [output.gsm] [sox|gst] [alaw|ulaw]"
   exit
fi

  IN=$1
 OUT=$2
TOOL=$3
 ENC=$4

function conv1()
{
   if [ $ENC == "alaw" ];then
      sox $IN -r 8000 -c 1 -e a-law $OUT resample -ql
   else
      sox $IN -r 8000 -c 1 -e u-law $OUT resample -ql  #default
   fi

   #notes:
   #the output file extension (wav or gsm) will change how sox performs the encoding
   #use .wav for sipp RTP
      Encoding: u-law                    Encoding: A-law
      Channels: 1 @ 14-bit               Channels: 1 @ 13-bit
   #use .gsm for asterisk music on hold
      Encoding: GSM
      Channels: 1 @ 16-bit

}

function conv2()
{
   if [ $ENC == "alaw" ];then
      gst-launch  filesrc location=$IN \
      ! wavparse \
      ! audioconvert \
      ! audioresample \
      ! alawenc \
      ! audio/x-alaw, rate=8000, channels=1 \
      ! wavenc \
      ! filesink location=$OUT
   else
      gst-launch  filesrc location=$IN \
      ! wavparse \
      ! audioconvert \
      ! audioresample \
      ! mulawenc \
      ! audio/x-mulaw, rate=8000, channels=1 \
      ! wavenc \
      ! filesink location=$OUT
   fi

   # notes: 
   # file output extension of wav and gsm are interchangeable in the converted format
}

if [ $3 == "gst" ];then
   conv2
else
   conv1
fi
查看更多
乱世女痞
4楼-- · 2019-02-20 08:16

I was looking for different WAV file encodings and found a lot of them on Wikipedia.

I've found one file (8,000 Hz µ-Law) that works correctly with the rtp_stream="8kulaw.wav,-1,0" exec parameter.

This is the file information:

ubuntu@mylinux:~/$ file 8kulaw.wav
8kulaw.wav: RIFF (little-endian) data, WAVE audio, ITU G.711 mu-law, mono 8000 Hz

I've tried to encode this file to the exact same configuration using this Sox command but it did NOT worked:

sox -r 8000 -e u-law sorry_dave.wav sorry_dave4.wav
查看更多
登录 后发表回答