在python中通过调制解调器发送wav声音 [英] Send wav sound through modem in python

查看:39
本文介绍了在python中通过调制解调器发送wav声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 python 和 linux 中制作一个自动应答和呼叫机,但到目前为止我只能拨打一个号码.在发送声音或录制它们时,我没有成功.过去一周我一直在为这个问题而苦苦挣扎,到目前为止还没有找到解决方法.

I am trying to make an automatic answering and calling machine in python and linux, but so far I was able to only call a number. When it comes to sending sounds or recording them I had no success. I have been struggling with this problem for the past week and so far could not find a way to solve it.

我使用的调制解调器是 Conexant Systems (Rockwell)

The modem I am using is a Conexant Systems (Rockwell)

这是我正在使用的代码:

Here is the code I am using:

import serial
import wave
import time

def initializePhone():
    phone = serial.Serial('/dev/ttyACM0', 112500, timeout=5)
    phone.write('AT'.encode())
    phone.write('AT+FCLASS=8')
    phone.write('AT+VSM=0,8000')
    return phone

def call(number):
    command = 'ATDT'+str(number)
    phone.write(command.encode())


def sendMusic(phone, music):
    cont = True
    while cont:
        frame = music.readframes(1024)
        if frame == '':
            cont = False
        ser.write(b"".join(frame))


def main():
    phone = initializePhone()
    music = wave.open('wood.wav','r')
    call('555555')
    time.sleep(10)
    sendMusic(phone, music)


if __name__=='__main__':
    main()

将不胜感激任何帮助.

推荐答案

找到了我的脚本中缺少的命令.这是带有修复程序的新版本.在发送音频数据之前我错过了AT+VTX"命令.

Found the commands that were lacking on my script. Here is the new version with the fix. I was missing the "AT+VTX" command before sending the audio data.

import serial
import wave
import time

def initializePhone():
    phone = serial.Serial('/dev/ttyACM0', 112500, timeout=5)
    phone.write('AT\r\n'.encode())
    phone.write('AT+FCLASS=8\r\n'.encode())
    phone.write('AT+VSM=0,8000\r\n'.encode())
    return phone

def call(number):
    command = 'ATDT'+str(number)+'\r\n'
    phone.write(command.encode())


def sendMusic(phone, music):
    phone.write('AT+VTX\r\n'.encode())
    cont = True
    while cont:
        frame = music.readframes(1024)
        if frame == '':
            cont = False
        ser.write(b"".join(frame))


def main():
    phone = initializePhone()
    music = wave.open('wood.wav','r')
    call('555555')
    time.sleep(10)
    sendMusic(phone, music)


if __name__=='__main__':
    main()

这篇关于在python中通过调制解调器发送wav声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆