How to get sound in a Linux Hyper-V VM (works on ubuntu - but should work on others)

cereberus

Well-known member
Power User
VIP
Local time
2:15 PM
Posts
380
In a previous post, I showed how to get sound on an ubuntu Hyper-VM build but it was pretty complicated.

I came across a simpler method using ffmpeg


Basic steps are as follows:

1) install xrdp so you can get enhanced mode.

I used this for ubuntu


2) install pulseaudio
Code:
sudo apt update

Code:
sudo snap install pulseaudio

3) install ffmpeg on Windows - I chose ffmpeg-N-103679-g7bbad32d5a-win64-gpl (see 1st link for details)

4) run this in powershell with admin rights


Code:
ffplay -nodisp -ac 2 -acodec pcm_s16le -ar 48000 -analyzeduration 0 -probesize 32 -f s16le -i udp://0.0.0.0:18181?listen=1

It runs and jumps to a cmd file and sort of stops dead as it executes - that is how it works.

With a little effort, you could auto start this using Task Scheduler I am sure. I just created a .bat file. This needs to be run each time you start windows (if you intend to use Linux with sound)

5) install ffmpeg on ubuntu vm


Code:
sudo snap install ffmpeg

6) Setup link to pulse audio

Code:
pactl load-module module-null-sink sink_name=remote


7) Start audio


Code:
ffmpeg -f pulse -i "remote.monitor" -ac 2 -acodec pcm_s16le -ar 48000 -f s16le "udp://192.168.1.198:18181"

Note: Change IP address for IP address of your Linux VM. Mine is 192.168.1.198. Look in network settings in Linux VM.

8) Kick start process

Sometimes you need to kick start process by running following command.

Code:
pulseaudio - k


It takes a few seconds to kick in.


You have to repeat steps 6 and 7 (and 8 if applicable) each time you restart Linux. Guys cleverer than me will work out how to create a batch file to do this on start I am sure.


You get a slight time delay but you can correct this in VLC. Again, guys cleverer than me will work out how to have a permanent delay (+ or -) with ffmpeg.
 
Last edited:

My Computer

System One

  • Operating System
    Windows 10 Pro + others in VHDs
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Vivobook 14
    CPU
    I7
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    N/A
    Screen Resolution
    1920x1080
    Hard Drives
    1 TB Optane NVME SSD, 1 TB NVME SSD
    PSU
    Yep, got one
    Case
    Yep, got one
    Cooling
    Stella Artois
    Keyboard
    Built in
    Mouse
    Bluetooth , wired
    Internet Speed
    72 Mb/s :-(
    Browser
    Edge mostly
    Antivirus
    Defender
    Other Info
    TPM 2.0

johnlgalt

Antidisestablishmentarianistentarianist
Power User
VIP
Local time
9:15 AM
Posts
1,922
Location
3rd Rock
Ye, gods, this is 1000x more simple than when I fought with (repeatedly) ALSA trying to get sound on my previous rig in Gentoo.

Thanks!
 

My Computers

System One System Two

  • Operating System
    Windows 10 Pro X64
    Computer type
    PC/Desktop
    Manufacturer/Model
    HomeBrew
    CPU
    AMD Ryzen 9 3950X
    Motherboard
    MSI MEG X570 GODLIKE
    Memory
    4 * Corsair Vengeance 32 GB 3600 MHz
    Graphics Card(s)
    eVGA GeForce GTX 970 SSC ACX 2.0 (04G-P4-3979-KB)
    Sound Card
    Realtek® ALC1220 Codec
    Monitor(s) Displays
    2 * Lenovo LT2323pwA Widescreeen
    Screen Resolution
    2* 1920*1080
    Hard Drives
    3x Sabrent Rocket PCIe Gen4 NVMe M.2 1 TB SSD (SB-ROCKET-NVMe4-1TB)
    SanDisk Ultra SDSSDHII-960G-G25 960 GB SATA III SSD
    Crucial MX100 CT256MX100SSD1 256GB SATA III SSD
    2 * Seagate Barracuda 7200.12 ST31000528AS 1TB 7200 RPM --> RAID1
    PSU
    PC Power & Cooling’s Silencer Series 1050 Watt, 80 Plus Platinum
    Case
    Fractal Design Define 7 XL Dark ATX Full Tower Case
  • Operating System
    Windows 10 x64 Pro build 21H1
    Computer type
    Laptop
    Manufacturer/Model
    Dell Latitude E5470
    CPU
    Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 2501 Mhz, 2 Core(s), 4 Logical Processor(s)
    Motherboard
    Dell
    Memory
    16 GB
    Graphics card(s)
    Intel(R) HD Graphics 520
    Sound Card
    Intel(R) HD Graphics 520 + RealTek Audio
    Monitor(s) Displays
    Dell laptop display 15"
    Screen Resolution
    1920 * 1080
    Hard Drives
    Toshiba 128GB M.2 22300 drive
    INTEL Cherryvill 520 Series SSDSC2CW180A 180 GB SATA III SSD
    PSU
    Dell
    Case
    Dell
    Cooling
    Dell
    Mouse
    Logitech MX Master (shared) | Dell TouchPad
    Keyboard
    Dell
    Internet Speed
    AT&T LightSpeed Gigabit Duplex
    Browser
    Edge Chromium | Chrome | Firefox Nightly | Brave
    Antivirus
    Defender + MB4

cereberus

Well-known member
Power User
VIP
Thread Starter
Local time
2:15 PM
Posts
380
Ye, gods, this is 1000x more simple than when I fought with (repeatedly) ALSA trying to get sound on my previous rig in Gentoo.

Thanks!
Although article says you do not need to be in enhanced mode, I found step 7 falls over with an error if in basic mode.
 

My Computer

System One

  • Operating System
    Windows 10 Pro + others in VHDs
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Vivobook 14
    CPU
    I7
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    N/A
    Screen Resolution
    1920x1080
    Hard Drives
    1 TB Optane NVME SSD, 1 TB NVME SSD
    PSU
    Yep, got one
    Case
    Yep, got one
    Cooling
    Stella Artois
    Keyboard
    Built in
    Mouse
    Bluetooth , wired
    Internet Speed
    72 Mb/s :-(
    Browser
    Edge mostly
    Antivirus
    Defender
    Other Info
    TPM 2.0
Top Bottom