[pulseaudio-discuss] Map sink-input to virtual microphone
Arun Raghavan
arun at arunraghavan.net
Wed Dec 23 02:36:35 UTC 2020
On Tue, 22 Dec 2020, at 2:04 AM, guest271314 wrote:
> This is the code that I cobbled together from your post,
> https://askubuntu.com/questions/60837 and
> https://aweirdimagination.net/2020/07/19/virtual-microphone-using-gstreamer-and-pulseaudio/
>
> pactl load-module module-combine-sink \
> sink_name=Web_Speech_Sink slaves=$(pacmd list-sinks | grep -A1 "*
> index" | grep -oP "<\K[^ >]+") \
> sink_properties=device.description="Web_Speech_Stream" \
> format=s16le \
> channels=1 \
> rate=22050
>
> pactl move-sink-input $(pacmd list-sink-inputs|tac|perl
> -E'undef$/;$_=<>;/speech-dispatcher-espeak-ng.*?index: (\d+)\n/s;say
> $1') Web_Speech_Sink
>
> pactl load-module module-remap-source \ master=Web_Speech_Sink.monitor
> \ source_name=Web_Speech_Monitor \
> source_properties=device.description=Web_Speech_Output
>
> Using this approach I am able to capture output from only
> speech-dispatcher-espeak-ng module using
>
> navigator.mediaDevices.getUserMedia({audio: true})
> .then(async stream => {
> const [track] = stream.getAudioTracks();
> const devices = await navigator.mediaDevices.enumerateDevices();
> const device = devices.find(({label}) => label ===
> 'Web_Speech_Output');
> track.stop();
> console.log(devices, device);
> return navigator.mediaDevices.getUserMedia({audio: {deviceId: {exact:
> device.deviceId}}});
> })
> .then(stream => {
> const recorder = new MediaRecorder(stream);
> recorder.ondataavailable = e =>
> console.log(URL.createObjectURL(e.data));
> const synth = speechSynthesis;
> const u = new SpeechSynthesisUtterance('test, test, then test again');
> u.onstart = e => {
> recorder.start();
> console.log(e);
> }
> u.onend = e => {
> recorder.stop();
> recorder.stream.getTracks().forEach(track => track.stop());
> console.log(e);
> }
> synth.speak(u);
> });
>
> Can the pactl and pacmd code be reduced?
Almost certainly. The module-combine-sink can probably get a manual list of slave devices if you know the name of the physical sink, and it should also be possible to use `pactl move-sink-input <sink name>` instead to avoid the second bit of Perl munging.
-- Arun
More information about the pulseaudio-discuss
mailing list