scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

Use phone as a microphone

Open Grafcube opened this issue 2 years ago • 7 comments

  • [x] I have checked that a similar feature request does not already exist.

I use my phone as a mic for my desktop by setting --audio-source=mic and then using Pipewire to connect it to a virtual source. It would be a lot easier to have some flag that does this automatically since it also plays whatever the mic picks up. Using --no-audio-playback doesn't work because I also disable video, so I also have to use Pipewire to disable the mic audio from being played.

Grafcube avatar Aug 01 '23 09:08 Grafcube

@Grafcube would you mind sharing your Pipewire config for it?

Cruaier avatar Jun 24 '24 06:06 Cruaier

would you mind sharing your Pipewire config for it?

Unfortunately I didn't make a config for it. I manually set it up using qpwgraph. I also don't do it anymore since I got a new microphone.

Grafcube avatar Jun 24 '24 07:06 Grafcube

I don't get it working in Pipewire trying to use v4l2 (with pw-v4l2)...hopefully the maintainers have the motivation to switch away from v4l2 to Pipewire. There will probably another way to get it done...

Cruaier avatar Jun 26 '24 14:06 Cruaier

would you mind sharing your Pipewire config for it?

Unfortunately I didn't make a config for it. I manually set it up using qpwgraph. I also don't do it anymore since I got a new microphone.

I would extremely grateful to you if you could share how did you do it with qpwgraph as I am trying and failing for hours.

How did you create virtual source?

EatedPantsu avatar Aug 14 '24 13:08 EatedPantsu

would you mind sharing your Pipewire config for it?

Unfortunately I didn't make a config for it. I manually set it up using qpwgraph. I also don't do it anymore since I got a new microphone.

I would extremely grateful to you if you could share how did you do it with qpwgraph as I am trying and failing for hours.

How did you create virtual source?

I referred to this documentation to create the source. I don't remember if I used the exact same command or if I made changes to it but it should be a good starting point.

https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Virtual-Devices#create-a-source

Grafcube avatar Aug 15 '24 07:08 Grafcube

Thanks a a lot! It set me on the right track!

EatedPantsu avatar Aug 15 '24 10:08 EatedPantsu

+1ing this as it would be very convenient as I do not have an external microphone available.

Whovian9369 avatar Oct 11 '24 01:10 Whovian9369

How did you create virtual source?

pactl load-module module-null-sink media.class=Audio/Source/Virtual sink_name=scrcpy_mic sink_properties=device.description="Scrcpy"

If it helps anyone, then you can easily connect it with qpwgraph. I am not sure how to do it in the command line as to create a script that does it all. If anyone shares a solution I would be grateful

iliqiliev avatar Jan 07 '25 21:01 iliqiliev

YMMV, but here is another solution that I personally use:

  1. pactl load-module module-pipe-source source_name="android" channels=2 format=s16 rate=48000 file=/tmp/mic_pipe (might need to tweak chan/format/rate based on format from the device)
  2. Leave parec -d android --raw > /dev/null running in the bg (needed as this is a pipe - if nothing is consuming audio when scrcpy is started and stopped, you may get issues)
  3. scrcpy --no-video --no-window -N --audio-source=mic --audio-codec=raw --record-format=wav --record=/tmp/mic_pipe --audio-buffer=10 --audio-output-buffer=10 (buffer values eyeballed, might need tweaking)

Ristovski avatar Jan 07 '25 22:01 Ristovski

Thank you, I created a simple script that combines everything into one so it's easy

#!/usr/bin/sh

LATENCY=125
MODULE_ID=$(pactl load-module module-pipe-source source_name="Scrcpy" channels=2 format=16 rate=48000 file=/tmp/scrcpy_pipe)

parec --raw > /dev/null &

scrcpy --no-video --no-window --no-playback --audio-source=mic --audio-codec=raw --record-format=wav --record=/tmp/scrcpy_pipe --audio-buffer=$LATENCY --audio-output-buffer=10 

pactl unload-module $MODULE_ID

I've set the latency high by default to avoid problems when the adb connection is over tcpip. Hope it helps somebody :)

iliqiliev avatar Jan 08 '25 12:01 iliqiliev