Re: Map sink-input to virtual microphone

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

On Tue, Dec 22, 2020 at 2:53 AM Arun Raghavan <arun@xxxxxxxxxxxxxxxx> wrote:
On Mon, 21 Dec 2020, at 9:52 AM, guest271314 wrote:
> A virtual microphone can be created using module-remap-source
> https://aweirdimagination.net/2020/07/19/virtual-microphone-using-gstreamer-and-pulseaudio/
>
> pactl load-module module-remap-source \ master=virtmic.monitor
> source_name=virtmic \
> source_properties=device.description=Virtual_Microphone
>
> AFAICT a sink-input cannot be set as the source for the virtual microphone.
>
> A sink-input can be recorded using parec or parecord --monitor-stream option
>
> parecord -v -r --monitor-stream=26 --file-format=wav output.wav

> How to set a sink-input as source for the virtual microphone so that
> the output of the sink-input is still played back to speakers or
> headphones and simultaneously is the source of the virtual microphone?

You could use module-combine-sink to play that sink input to a null-sink and the real sink, and then use the null-sink's monitor as your source.

-- Arun
_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux