Search code examples
pulseaudio

Why is there a difference in latency between null-sink and actual devices in pulseaudio?


I'm trying to create a phone autoresponder software using pulseaudio and amazon connect.

So I use two null-sinks in pulseaudio to pass sound to speech recognition and speech synthesis. However, I did notice a lantency that appeared to be from PULSEAUDIO.

I have prepared the following simple script and compared it with the actual device.

This program was run under python3.6 and centOS7.

#!/usr/bin/env python3

import time
import subprocess

t1=time.time()
subprocess.run(["pacat","--device=0","/usr/share/sounds/alsa/Noise.wav"])
print(time.time()-t1)
t1=time.time()
subprocess.run(["pacat","--device=1","/usr/share/sounds/alsa/Noise.wav"])
print(time.time()-t1)

The output of this program is now as follows.

0.7789342403411865
2.532053232192993

Why is there such a difference in lantency? Also, is there any way to reduce the latency of null-sink?

In addition, since we plan to use it on fargate on eks, it is difficult to change the value of the NICE or to schedule it in real time.


Solution

  • A null-sink is created with a default latency of around two seconds. So the latency was 2 seconds unless the stream I created required it.