我需要帮助,以理解为什么当你发送音频给相机,你听到丑陋,非常快。摄像机配置为音频编解码器G711Ulaw。
我正在做的工作如下:
这是在非公开场合听到的,但正如我一开始解释的那样,我听错了,我扭曲了,非常快。我做错了什么?
问候
发布于 2018-05-24 18:03:26
我已经找到了为什么-这与编码无关。我已经编写了一个C#应用程序来测试这一点,如果你以预期的速度发送数据(每秒8000个样本),那么它将正确运行。
我以数据包的形式发送音频数据(目前有160个字节,但是试验了最优值,但只要延迟是正确的,就不会有多大影响),并在再次发送之前延迟适当的时间,以便在一秒钟内发送正确的样本数量。
发布于 2022-09-29 18:03:38
我在github上发现了一个有趣的这项目,它帮助我创建了一个简单的应用程序,可以使用python将音频发送到摄像机:
import urllib.request
import requests
import socket
import time
class SocketGrabber:
""" A horrible hack, so as to allow us to recover
the socket we still need from urllib """
def __init__(self):
self.sock = None
def __enter__(self):
self._temp = socket.socket.close
socket.socket.close = lambda sock: self._close(sock)
return self
def __exit__(self, type, value, tb):
socket.socket.close = self._temp
if tb is not None:
self.sock = None
def _close(self, sock):
if sock._closed:
return
if self.sock == sock:
return
if self.sock is not None:
self._temp(self.sock)
self.sock = sock
audio_file = "output.ulaw"
ip = "IPCAM"
username = "USER"
password = "PASS"
index = 1
base = f"http://{ip}"
chunksize = 128
sleep_time = 1.0 / 64
base_url = f"http://{username}:{password}@{ip}"
req = requests.put(
f"{base_url}/ISAPI/System/TwoWayAudio/channels/{index}/open")
mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(None, [base], username, password)
auth = urllib.request.HTTPDigestAuthHandler(mgr)
opener = urllib.request.build_opener(auth)
audiopath = f"{base}/ISAPI/System/TwoWayAudio/channels/{index}/audioData"
with SocketGrabber() as sockgrab:
req = urllib.request.Request(audiopath, method='PUT')
resp = opener.open(req)
output = sockgrab.sock
def frames_yield(ulaw_data, chunksize=128):
for i in range(0, len(ulaw_data), chunksize):
for x in [ulaw_data[i:i + chunksize]]:
tosend = x + (b'\xff' * (chunksize - len(x)))
time.sleep(sleep_time)
yield tosend
with open(audio_file, 'rb') as file_obj:
ulaw_data = file_obj.read()
for dataframe in frames_yield(ulaw_data, chunksize):
output.send(dataframe)https://stackoverflow.com/questions/38336063
复制相似问题