Working on audio commands

This commit is contained in:
2025-09-01 23:01:08 +02:00
commit 343d1d2f93
19 changed files with 1932 additions and 0 deletions

164
Prerequisite.md Normal file
View File

@@ -0,0 +1,164 @@
# 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 & security****Microphone**
3. Enable **"Let apps access your microphone"**
4. Enable **"Let desktop apps access your microphone"**
### 2. WSL2 Configuration
#### 2.1 Update WSL2
```bash
# In PowerShell (Administrator)
wsl --update
wsl --shutdown
# Restart WSL2
```
#### 2.2 Install Audio Dependencies in WSL2
```bash
# In your WSL2 terminal
sudo apt update
sudo apt install pulseaudio pulseaudio-utils
```
#### 2.3 Verify PulseAudio Connection
```bash
# 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)
```bash
# 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)
```bash
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
```bash
# 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:**
```bash
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
```bash
pulseaudio --check -v
# Should display: "User-configured server at unix:/mnt/wslg/PulseServer"
```
### Test 2: Available Devices
```bash
pactl list sources short
# Should list at least RDPSource
```
### Test 3: Python Recording
```bash
python main.py
# Should display device list and allow recording
```
## 📚 Additional Resources
- [Official WSL Audio Documentation](https://docs.microsoft.com/en-us/windows/wsl/)
- [PulseAudio Documentation](https://www.freedesktop.org/wiki/Software/PulseAudio/)
- [WSL Audio Issues on GitHub](https://github.com/microsoft/WSL/issues?q=audio)
## ⚠️ 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
```