1

I can't for the life of me figure this out.. I'm trying to take data received on a network connection, and then pipe it to a subprocess, which will stream the data to my soundcard via aplay.

I've managed to do this, but it pauses briefly while it receives the data.

while True: 
    data = sock.recv(1024)
    p1.stdin.write(data)

What is the best way to setup a pipe that will stream from a network connection indefinitely? Setting up multiprocessing or threading to do this?

Thanks!

4

1 回答 1

0

播放声音特别棘手 - 人耳对声音播放中的任何中断都很敏感,并且感知质量会很差。此外,您永远无法预测网络中的延迟/抖动/延迟。因此,以下模型是最好的:

  1. 多线程 - 一个线程从网络接收并提交到队列。另一个线程从队列中读取并将音频数据提交给声卡。
  2. 有一个可以保存 1-2 秒数据的抖动缓冲区。(取决于您的应用程序。如果您正在编写语音聊天应用程序,则应缓冲不超过 150 毫秒的数据)。
  3. 如果此缓冲区中的数据用完,请在开始播放之前重新缓冲。播放中的暂时暂停比音频中的持续中断要好。
于 2013-06-12T01:05:21.953 回答