Using a phone as a microphone

My laptop’s fan sounds like a disgruntled koala right now, and none of the noise reduction programs I could get my hands on worked well enough to make its microphone usable.
I can’t bother to fix it or buy a microphone so I decided to use my phone’s microphone as my laptop’s microphone.
There is this app AudioRelay but it asked for my soul as payment, and only I am allowed to torture my own soul, so I got to it.
I found this script mic_over_mumble. There’s just one small problem: I’m a noob. I have no clue about pipewire, also what’s mumble?
Anyways I bashed my head against the keyboard for a while, here’s the result:

  ...
  # Enable pipewire.
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;
  };

  services.pipewire.extraConfig.pipewire."97-null-sink" = {
    "context.objects" = [
      {
        factory = "adapter";
        args = {
          "factory.name" = "support.null-audio-sink";
          "node.name" = "Null-Sink";
          "node.description" = "Null Sink";
          "media.class" = "Audio/Sink";
          "audio.position" = "FL,FR";
        };
      }
      {
        factory = "adapter";
        args = {
          "factory.name" = "support.null-audio-sink";
          "node.name" = "Null-Source";
          "node.description" = "Null Source";
          "media.class" = "Audio/Source";
          "audio.position" = "FL,FR";
        };
      }
    ];
  };
  services.pipewire.extraConfig.pipewire."98-virtual-mic" = {
    "context.modules" = [
      {
        name = "libpipewire-module-loopback";
        args = {
          "audio.position" = "FL,FR";
          "node.description" = "Mumble as Microphone";
          "capture.props" = {
            # Mumble's output node name.
            "node.target" = "Mumble";
            "node.passive" = true;
          };
          "playback.props" = {
            "node.name" = "Virtual-Mumble-Microphone";
            "media.class" = "Audio/Source";
          };
        };
      }
    ];
  };
  
  # Mumble server.
  services.murmur = {
    enable = true;
    bandwidth = 540000;
    bonjour = true;
    password = "choose_your_own_password";
    autobanTime = 0;
  };
  ...
  home.packages = with pkgs; [
    ...
    # Mumble client.
    mumble
    ...
  ];
  ...
  # Open ports in the firewall.
  networking.firewall.allowedTCPPorts = [
    # Mumble Murmur server port
    64738
  ];
  networking.firewall.allowedUDPPorts = [
    # Mumble Murmur server port
    64738
  ];

The firewall almost got me, didn’t know it was enabled by default in Nixos.

So here’s how it works:

  • Open mumble on PC.
  • The configuration wizard can be ignored, or not.
  • Add your server with the address 127.0.0.1 (localhost) and your chosen password in nix configuration.
  • You should now be connected to the server on the same PC.
  • The PC client should be muted but not deafened.
  • Go to configure/settings
  • In audio input tab choose PulseAudio as system interface and Null Source as its device.
  • in audio output tab choose PulseAudio as system interface and Null Sink as its device.
  • Connect phone to the same network as PC. I used a USB cable and tethering for least delay.
  • Install phone client. On Android it’s called Mumla.
  • Add the server using your PC’s local IP address (something like 192.168.xx.xx or 172.16to31.xx.xx or 10.xx.xx.xx) and the chosen password.
  • Connect to server on phone.
  • Now you should be able to choose “Mumble as Microphone” on your PC on any application that asks for an audio source.

As I said I’m a noob, so forgive any mistake I’ve made.
I hope this helps somebody not waste as much time as I did.

11 Likes

Wow this actually cool and super cursed at the same time, congrats for figuring it out! What would do if I wanted to set this up myself, is somehow stream the microphone audio data from my phone to the PC via RTMP, it’s meant for this kind of stuff. But getting a Android program that can take microphone input and then send it as RTMP might be difficult, dunno if such a thing exists. Anyway, very cool solution, have fun using it for whatever you need it :slight_smile:

Quick search led me to GitHub - begeekmyfriend/yasea: RTMP live streaming client for Android which looks like what i’d need for the rtmp setup. Streams video too!

1 Like

Thanks for the alternative solution. What’s the Nixos / Linux RTMP client you would choose?
Edit: Incredibly VLC supports RTMP, I’ll try this next time I need to stream audio or video, thanks.

Not sure, but ffmpeg can probably somehow shove input into pipewire. If not i seem to recall pipewire itself can ingest rtmp somehow.

2 Likes

Ffmpeg can definitely do that. RTMP is often used on surveillance cameras, go2rtc is a popular restreaming daemon.

1 Like

I personally used Droidcam for a while when I didn’t have a proper webcam.
Maybe another alternative to look into.

https://droidcam.app/

2 Likes