Skip to content

How to play audio files as input?

Hello all. I'm looking at playing an audio file as an input. I want to use this to be able to play audio files through discord, and have the other call participants hear it (an audio macro?). Thanks!

65 points19 comments
Open on Reddit
About this post
Posted
Archived
Score
65 · 93% up
Kind
Text
ID
klmyec

Author

9
posts
24
comments
1
media
View profile

20 comments

If you don't need your own voice during it, switch the discord recording to the "Monitor of" your audiocard in pulseaudio/pavucontrol.

if you want this more fine grained you'll have to specify a bit more what goals you have. If you just want to record a single program allocate a virtual-sink move the program you want to use as an input to that virtual sink and record from there.

See e.g. this thread https://bbs.archlinux.org/viewtopic.php?id=261326 for a bit of a more extensive example

27 points

More links:

module-null-sink: Create a virtual sink to play your audio to. You can use a "Monitor of ..." device to capture from it.

module-loopback: Route audio from a source (microphone) to a sink.

module-combine-sink: Combine two sinks into one.

You can now route your microphone from your microphone to a sink using loopback, combine that sink with a null sink and then capture from the monitor of the combined sink.

13 points

Ideally I would want to be able to talk at the same time as i play the input to discord (it only needs to play to discord and nothing else) but thank you.

1 points

You could also dabble your feet in Jack, which will make it a lot easier if you ever need to do anything more complicated. Then you can literally just use Carla to plug your sound and mic into the sink and call it a day.

4 points

I've done this very recently. Here's how I achieved it:

Create a new file ~/.config/pulse/default.pa with the following content:

.include /etc/pulse/default.pa

load-module module-null-sink sink_name=virtual1 sink_properties=device.description="virtual1-hearshare"
load-module module-null-sink sink_name=virtual2 sink_properties=device.description="virtual2-share"

load-module module-loopback source=virtual1.monitor latency_msec=1
load-module module-loopback source=virtual1.monitor sink=virtual2 latency_msec=1
load-module module-loopback sink=virtual2 latency_msec=1

What this does is setup two null sinks (one for the stuff you want to both hear and share, called virtual1-hearshare, and one for the stuff you want to share, called virtual2-share) and three loopbacks to send stuff in and out of those.

Next, install pavucontrol and restart your session.

Open Pavucontrol (aka PulseAudio Volume Control) and go to the playback tab. At the bottom, select "All streams". Make sure that one of the two loopbacks from "Monitor of virtual1-hearshare" goes into your headphones and the other goes into virtual2-share.

Then, go to the recording tab. Make sure that one of the two loopbacks to virtual2-share comes from virtual1-hearshare and the other comes from your microphone.

Nice. Now, when you want to share audio to Discord, do the following:

  • Enter the Discord call, start playing your audio file and pause it.
  • Open Pavucontrol on the "playback" tab
  • Next to your audio/video player, select "virtual1-hearshare" as its output instead of your headphones.
  • Go to the recording tab.
  • Next to the Discord input stream (usually called "WebRTC VoiceEngine"), select "virtual2-share" as its input instead of your microphone.

After doing this, both you and your friends on Discord should be able to hear the audio (not all of the audio going to your headphones, only the audio from the program you selected), and also they should be able to hear you.

17 points

This is one of those good replies you sometimes see around. You wouldn't happen to have some good resources? Especially understanding how to setup default.pa?

4 points

If you run man pulse-cli-syntax you will find an explanation of the syntax of default.pa. All of those commands can be also run from a shell by prepending pacmd to them.

What you will most probably want to do with default.pa is load and configure modules. You can find a list of the modules and their configuration options at https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/.

The two modules used in my answer are module-null-sink and module-loopback.

3 points

Be aware that the codec/bandwidth discord uses for speech absolutely butchers non-spoken content (like music or even just TV shows with bgm mixed with voice lines). I've previously tried this as a workaround for discord's lack of support for capturing desktop audio on Linux when streaming to friends but the results were not acceptable to end users even when they were fine if I recorded the monitor stream locally using VLC (and this was after turning off all discord's post processing)

5 points

I do this constantly for Zoom calls and podcasting.

If you want to do this on the regular, it might be easier to buy a small audio mixer and a dynamic mic. If you get one with USB in/out then that's all the better. I personally own a Yamaha MG10XU and a cheap Behringer dynamic mic for doing podcasts, but I'm upgrading my mic soon. The USB gives you an additional in and out channel, and you can send the USB stereo in on monitor mode so it only goes to your headphones/monitor and not your output.

You can also pick up a 1/8" TRS stereo to RCA cable and plug your cellphone in as a second audio source into the channel 5/6 input, which will give you a dedicated source for your media. I do this by using a second sound card with a hefty bit of pulseaudio config, but you can do it without reconfiguring pulse at all. Anything you mix between your cell and your mic will be used as your audio input to discord.

Note that the USB in from the MG10XU is a bit on the weak side so you'll likely want to boost it in pavucontrol or set up an analog main out into your line in. This second way can be tricky depending on how your sound card is configured. If it comes out sounding crunchy, then the sound card is adding amplification, which you don't want.

So, the configuration will go like this

  • Discord input: MG10XU/Analog stereo line in
  • Discord output: MG10XU
  • MG10XU inputs:
    • Channel 1: Dynamic mic
    • Channel 5/6: Cellphone/digital audio device/PC media out
    • Channel 9/10 (USB In): Discord output (enable To MON switch, set input to USB)
2 points

I think the simplest solution would be to just use Discord's built-in screen-sharing functionality, which I'm pretty sure also shares your computer's audio.

1 points

Not on Linux it doesn't - apparently they're waiting for Pipewire to be more widespread.

2 points
unknown author

Deleted before we saved it.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.