Enable audio in QEMU Virtual Machine

This article is specifically on how to enable audio in QEMU Virtual Machine. We have already discussed how to setup Virtual Machine using QEMU in Ubuntu here. We assume you have got everything setup as mentioned in the said article.

Prior to that, a bit about sound card. A sound card can be an internal or external component, which is used to send and receive audio signals.

In addition to, a basic sound card consists of mainly – Analog to Digital Converter, Digital to Analog Converter, Peripheral Component Interconnect (PCI) Interface and I/O connections. It is worth mentioning here that, I/O connections on a sound card are color coded. For instance, Pink for Analog microphone audio input and Lime for Analog line level audio output.

We can use a sound card through device driver. A device driver, low-level instruction set, manages devices connected to our computer.

Furthermore, we assume you have already installed the relevant audio device drivers in both host as well as guest Operating Systems.

Enable audio in QEMU Virtual Machine

We need to first look for valid sound cards. Therefore, open a terminal and issue the following to list available sound cards –

qemu-system-x86_64 -soundhw help

where,

-soundhw – to enable the selected audio hardware,

help is to list available sound cards.

Now, we can enable the sound card from the list through the command –

qemu-system-x86_64 -soundhw <sound_card_name> disk_image.qcow2

For instance – to enable Intel HD Audio,

qemu-system-x86_64 -soundhw hda disk_image.qcow2

If in case, you would want to enable all the available sound cards. That is also possible through command –

qemu-system-x86_64 -soundhw all disk_image.qcow2

where,

sound_card_name is being replaced by all.

Also, you can replace qemu-system-x86_64 with qemu-system-i386 for i386 architecture.

In conclusion, we have discussed how to enable audio in QEMU Virtual Machine.

Additional Info –

If you came here after reading the above mentioned article – Setup Virtual Machine using QEMU in Ubuntu

Then, issue the following in terminal –

qemu-system-x86_64 -soundhw <sound_card_name> -cpu host -enable-kvm -m RAM_size -smp number_of_cores  -drive file=/path/to/disk_image,format=qcow2

For instance – to enable Intel HD Audio,

qemu-system-x86_64 -soundhw hda -cpu host -enable-kvm -m 2048 -smp 2 -drive file=/path/to/disk_image/test-img.qcow2,format=qcow2

Similarly, you can use all in place of <sound_card_name> to enable all the available sound cards.