Files
MyTTSClient/Prerequisite.md

4.3 KiB

WSL2 Audio Configuration for Microphone Access

This guide explains how to configure Windows microphone access from WSL2 for the MyTTSClient project.

🎯 Objective

Enable a Python application in WSL2 to access the Windows microphone for audio recording and transmission to a Wyoming server.

📋 Prerequisites

  • Windows 10 (Build 19041+) or Windows 11
  • WSL2 installed and configured
  • Linux Distribution (Ubuntu 20.04+ recommended)
  • Microphone connected and working in Windows

🔧 Step-by-step Configuration

1. Windows Permissions

1.1 Enable Microphone Access

  1. Open Windows Settings (Win + I)
  2. Navigate to Privacy & securityMicrophone
  3. Enable "Let apps access your microphone"
  4. Enable "Let desktop apps access your microphone"

2. WSL2 Configuration

2.1 Update WSL2

# In PowerShell (Administrator)
wsl --update
wsl --shutdown
# Restart WSL2

2.2 Install Audio Dependencies in WSL2

# In your WSL2 terminal
sudo apt update
sudo apt install pulseaudio pulseaudio-utils

2.3 Verify PulseAudio Connection

# Check connection to Windows server
pulseaudio --check -v

Expected Results:

  • N: [pulseaudio] main.c: User-configured server at unix:/mnt/wslg/PulseServer, refusing to start/autospawn.
  • E: [pulseaudio] core-util.c: Failed to create secure directory (see Troubleshooting section)

2.4 Environment Variables (if needed)

# Add to ~/.bashrc if issues persist
export PULSE_SERVER=unix:/mnt/wslg/PulseServer
export PULSE_RUNTIME_PATH="/mnt/wslg/runtime-dir/pulse"

# Reload
source ~/.bashrc

3. Test Audio Devices

3.1 List Audio Sources (microphones)

pactl list sources short

Example Output:

1    RDPSink.monitor    module-rdp-sink.c     s16le 2ch 44100Hz    SUSPENDED
2    RDPSource          module-rdp-source.c   s16le 1ch 44100Hz    SUSPENDED

3.2 Test with Python

# Install Python dependencies
pip install sounddevice numpy

# Test devices
python -c "import sounddevice; print(sounddevice.query_devices())"

Example Output:

  0 pulse, ALSA (32 in, 32 out)
* 1 default, ALSA (32 in, 32 out)

🔍 Diagnostics and Troubleshooting

Issue: "Permission denied" on /mnt/wslg/runtime-dir/pulse

Solution:

sudo mkdir -p /mnt/wslg/runtime-dir/pulse
sudo chown $USER:$USER /mnt/wslg/runtime-dir/pulse
chmod 700 /mnt/wslg/runtime-dir/pulse

Issue: "Error querying device -1"

Cause: PulseAudio cannot find audio devices

Solutions:

  1. Check Windows permissions (step 1.1)
  2. Restart WSL2: wsl --shutdown then relaunch
  3. Verify environment variables (step 2.4)

Issue: No input devices detected

Solutions:

  1. Test microphone directly in Windows
  2. Ensure microphone is not used by another application
  3. Restart Windows and WSL2

Issue: "RDPSource" instead of real microphone

Explanation: WSL2 uses RDP (Remote Desktop Protocol) to tunnel audio. RDPSource IS your Windows microphone.

🧪 Validation Tests

Test 1: PulseAudio Connection

pulseaudio --check -v
# Should display: "User-configured server at unix:/mnt/wslg/PulseServer"

Test 2: Available Devices

pactl list sources short
# Should list at least RDPSource

Test 3: Python Recording

python main.py
# Should display device list and allow recording

📚 Additional Resources

⚠️ Known Limitations

  1. Audio Latency: WSL2 may introduce additional latency
  2. Audio Quality: RDP compression may affect quality
  3. Permissions: Windows Updates may reset permissions
  4. Multi-user: Per-Windows-user configuration

🔄 Updates

This guide is based on WSL2 version 2.0+ and Windows 11. For earlier versions, additional steps may be required.


Version: 1.0
Last Updated: 2025-08-31
Tested On: Windows 11, WSL2 Ubuntu 22.04