Enabling sound in WSL Created 2020-08-01 | Updated 2020-08-01
https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/ https://www.freedesktop.org/wiki/Software/PulseAudio/Ports/Windows/Support/
PulseAudio を使ってWSL2 上でサウンドを再生できるようにしてみました。 Extraterm 上でMOC(Music on Console) を利用してみました。 Visual Studio Code のターミナルでも実行できます。
環境
Windows 10 Insider Preview Build 20180 [IP: 192.168.11.2]
PulseAudio for Windows 1.1
WSL2 (Ubuntu)
pulseaudio 13.99.1
moc 2.6-alpha3 (Theme: transparent-background)
Extraterm 0.52.0 (Theme: Extraterm Default)
構築 (Windows 10 側)
PulseAudio for Windows のダウンロードと展開 https://www.freedesktop.org/wiki/Software/PulseAudio/Ports/Windows/Support/
PulseAudio の設定
C:\tools\pulseaudio\etc\pulse\default.pa #load-module module-native-protocol-tcp load-module module-native-protocol-tcp auth-anonymous=1
C:\tools\pulseaudio\etc\pulse\default.pa #load-module module-waveout sink_name=output source_name=input load-module module-waveout sink_name=output source_name=input record=0
C:\tools\pulseaudio\etc\pulse\daemon.conf ; exit-idle-time = 20 exit-idle-time = -1
PulseAudio for Window の実行
C:\tools\pulseaudio\bin>pulseaudio.exe W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . W: [(null )] pulsecore/pid.c: Stale PID file , overwriting. W: [(null )] pulsecore/core.c: failed to allocate shared memory pool. Falling back to a normal memory pool. W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . W: [(null )] pulsecore/core-util.c: Secure directory creation not supported on Win32 . E: [(null )] daemon/main.c: Failed to load directory .
一度、pulseaudio.exe -Dを実行した方がよいかもしれません。 試しにhttp://192.168.11.2:4317にアクセスするとログが追記されます。 4. Windows ファイアウォールの許可要求に対して許可する
構築 (WSL 側)
パッケージのインストール
$ sudo apt install pulseaudio libasound2-plugins moc moc-ffmpeg-plugin
PulseAudio の設定
/etc/pulse/default.pa #load-module module-native-protocol-tcp load-module module-native-protocol-tcp
/etc/pulse/client.conf ; default-server = default-server = tcp:192.168.11.2
ALSA の設定
/etc/asound.conf pcm.!default { type pulse # If defaults.namehint.showall is set to off in alsa.conf, then this is # necessary to make this pcm show up in the list returned by # snd_device_name_hint or aplay -L hint.description "Default Audio Device" } ctl.!default { type pulse }
実行 (Windows 10 側)
タスクスケジューラでログイン時に実行
C : \tools \pulseaudio \bin \pulseaudio . exe - D
利用 (WSL 側)
Moc の実行
Moc の使い方は https://ktkr3d.github.io/2012/05/31/moc-music-on-console/