Skip to main content
 首页 » 编程设计

python之关于 PJSUA 和编解码器的问题

2025年02月15日10softidea

我在 Raspberrypi 上使用 PJSIP 2.7 和 Python,我有 2 个问题:

问题 1:

我怎么知道可用的编解码器? 我正在使用 enum_codecs() 方法列出编解码器,但它返回一个十六进制字符串数组:

infos = lib.enum_codecs() 
print infos 
 
codec:[<pjsua.CodecInfo instance at 0xb64c2620>, <pjsua.CodecInfo instance at 0xb64c2648>, <pjsua.CodecInfo instance at 0xb64c2670>, <pjsua.CodecInfo instance at 0xb64c2698>, <pjsua.CodecInfo instance at 0xb64c26c0>, <pjsua.CodecInfo instance at 0xb64c26e8>, <pjsua.CodecInfo instance at 0xb64c2710>, <pjsua.CodecInfo instance at 0xb64c2738>, <pjsua.CodecInfo instance at 0xb64c2760>, <pjsua.CodecInfo instance at 0xb64c2788>, <pjsua.CodecInfo instance at 0xb64c27b0>, <pjsua.CodecInfo instance at 0xb64c27d8>, <pjsua.CodecInfo instance at 0xb64c2800>, <pjsua.CodecInfo instance at 0xb64c2828>, <pjsua.CodecInfo instance at 0xb64c2850>] 

我怎么知道哪个是G711和G722?我希望我的端点使用 G722 编解码器。 关于类(class)的文档在这里:http://www.pjsip.org/python/pjsua.htm


问题 2:

如果我想在 Python 代码中使用与 pjsip 相同的音频设备,为什么会导致设备忙?我也尝试过 DMIX,但没有成功。

os.system("aplay -f S16_LE -c 2 -D plughw:1,0 /home/pi/beep.wav") 
aplay: main:722: audio open error: Device or resource busy 

任何帮助将不胜感激。

请您参考如下方法:

我终于找到了问题 1 和 2 的答案:

问题一的答案: 我可以通过在 Asterisk 端设置正确的编解码器来使用 g722 编解码器。

问题2的答案:

我的麦克风是一个 USB 设备 (hw 1),我的声卡是另一个 (hw 0)。 我不得不编辑我的 .asound.conf 文件并使用 dmix 设备进行播放。 这是我最终的工作 .asound.conf 文件:

pcm.!default 
{ 
type asym 
playback.pcm 
{ 
    type plug 
    slave.pcm "dmix" 
} 
capture.pcm  
{ 
    type plug 
    slave.pcm "hw:1,0" 
} 
} 

我现在可以在使用 pjsua 通话的同时播放声音。 这篇文章帮助我弄明白了:

Raspberry forum