Recently, I've been seeing audio issues with Zoom and the like in a
QEMU KVM guest Linux machine created via
virt-manager. Audio captured by my microphone would sound "roboty" and be noticeably laggy (at one point, the lag got close to half a minute). This got annoying quickly.
Some bug reports and posts out there describe solving the laggy recording by reconfiguring audio on the host. Others got around it by using an USB sound card, bypassing the host audio altogether. That seemed like overkill to me - it's 2020 and there really should be a cleaner way to fix audio lag. I also knew the issue doesn't come up when I run the same software on a VirtualBox guest, so I wasn't going to touch audio on the host unless I really had to (spoiler: I didn't).
Ultimately, an Arch forum post pointed me to a fairly lightweight solution that works. The same page also explains the mechanism causing the issue happening in the first place.
So if you're dealing with laggy audio, try this before doing anything else.
Run sudo virsh edit GUEST where GUEST is the name of the VM. This will open
an XML file with QEMU settings for your VM.
Once in the XML file, check the first line. It may look like this ...
<domain type='kvm'>
If it does, change it to this ...
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
This is so that virsh doesn't complain about the change we'll do next.
Then go to the end of the file, find the closing </domain> tag and add a
qemu:commandline setting just above it - like this:
<qemu:commandline>
<qemu:env name='QEMU_AUDIO_TIMER_PERIOD' value='200'/>
</qemu:commandline>
</domain>
Save the XML, start/restart your VM and check the recording lag then.
Did this help? Let me know! If it didn't, definitely let me know!