SongRec icon indicating copy to clipboard operation
SongRec copied to clipboard

Songrec does not have access to my speakers

Open Bundy01 opened this issue 3 years ago • 8 comments
trafficstars

Hi,

My bluetooth speakers are not accessible with Songrec. No problem with the ones integrated on my laptop.

Will it be possible to integrate bluetooth and wifi speakers?

Regards.

Bundy01 avatar Jun 28 '22 21:06 Bundy01

Same with pipewire here. Songrec only recognizes the integrated speaker, regardless the active one set in pipewire.

awsms avatar Aug 02 '22 00:08 awsms

I have the same issue. Currently, my workaround is to use Helvum to rewire it to my Bluetooth headphones. I think you could automate this with udev rules or using internal Pipewire configs but I don't really care and don't know either how to do so.

Before grafik After grafik

Toorero avatar Aug 15 '22 14:08 Toorero

Hello,

Thanks for reporting. I think that a correct way to ensure PipeWire compatibility and fix these issues could be to rewrite the audio interfacing part of the application in order to the use the GStreamer library instead of rodio (which has an ALSA-based backend and natively supports less formats, we already support interfacing with FFmpeg when available to circumvent this last issue).

Contributions are welcome on this is anyone would wish to get involved

Regards,

marin-m avatar Aug 18 '22 08:08 marin-m

Yeah, I have this same issue, and have also been working around it with Helvum. As far as I can tell, SongRec picks an output to monitor at random - it's certainly not always (in fact, IME, ever) the one that's currently active.

It might be best if individual outputs appeared as entries within SongRec's "Audio input" dropwdown. Indeed, this may already be the case for ALSA, since I see a sysdefault:CARD=sofhdadsp entry.

I'm using pipewire-pulse, which exposes the same API as PulseAudio, so SongRec should work very similarly to how it does with normal PulseAudio. I seem to get exactly the same behaviour regardless of whether I set SongRec's audio input to pipewire or pulse.

georgefst avatar Sep 14 '22 17:09 georgefst

Songrec doesn't even open for me, nor display any errors.

I am pretty sure it's the lack of pipewire support, but not sure how fix it with Helvum. Could you give some explanation how to, @georgefst?

BeyondMagic avatar Oct 10 '22 21:10 BeyondMagic

If Songrec doesn't even start, I don't think Helvum can help you.

georgefst avatar Oct 11 '22 16:10 georgefst

Yeah, I have this same issue, and have also been working around it with Helvum.

Got fed up of patching this manually every time, so I wrote a (needlessly robust and general) script:

#!/bin/bash

# tell Songrec to monitor the system's default output
# https://github.com/marin-m/SongRec/issues/103#issuecomment-1312496884

export SONGREC_BINARY_NAME=songrec

pw-dump > /tmp/pw-dump.json

export DEFAULT_SINK=$(cat /tmp/pw-dump.json | jq -r 'map(select(.type == "PipeWire:Interface:Metadata") | .metadata) | flatten | map(select(.key == "default.audio.sink") | .value.name) | .[]')
echo $DEFAULT_SINK

export DEFAULT_SINK_NODE_ID=$(cat /tmp/pw-dump.json | jq -r 'map(select(.type == "PipeWire:Interface:Node" and .info.props."node.name" == env.DEFAULT_SINK)) | .[] | .id')
echo $DEFAULT_SINK_NODE_ID

cat /tmp/pw-dump.json | jq -r 'map(select(.type == "PipeWire:Interface:Port" and .info.props."node.id" == (env.DEFAULT_SINK_NODE_ID|tonumber) and .info.props."port.monitor"))' > /tmp/pw-default-sink-ports.json
cat /tmp/pw-default-sink-ports.json | jq -r 'map(.info.props."object.path") | .[]'

export SONGREC_NODE_ID=$(cat /tmp/pw-dump.json | jq -r 'map(select(.type == "PipeWire:Interface:Node" and .info.props."application.process.binary" == "songrec")) | .[] | .id')
echo $SONGREC_NODE_ID

cat /tmp/pw-dump.json | jq -r 'map(select(.type == "PipeWire:Interface:Port"  and .info.props."node.id" == (env.SONGREC_NODE_ID|tonumber) and .info.direction == "input"))' > /tmp/pw-songrec-input-ports.json
cat /tmp/pw-songrec-input-ports.json | jq -r 'map(.info.props."object.path") | .[]'

for ((i=0; ;++i))
do
    export INDEX=$i
    IN=$(cat /tmp/pw-default-sink-ports.json | jq -r 'map(select(.info.props."port.id" == (env.INDEX|tonumber))) | .[].info.props."object.path"')
    echo $IN
    OUT=$(cat /tmp/pw-songrec-input-ports.json | jq -r 'map(select(.info.props."port.id" == (env.INDEX|tonumber))) | .[].info.props."object.path"')
    echo $OUT
    if [[ -n "$IN" && -n "$OUT" ]] && pw-link "$IN" "$OUT" ; then echo "linked" ; else break ; fi
done

https://xkcd.com/974/

georgefst avatar Nov 12 '22 14:11 georgefst

I'm not sure if this is related to this issue but I had same problem using bluetooth earphones. I wrote script after reading issue #58 to stop doing this manually when using different device:

#!/bin/sh

# recognizes only one song then exits
nohup songrec recognize -d default > shazam.txt &

# need to wait before songrec init
sleep 1

# expecting there will be only songrec
SOURCE_OUTPUT_ID=$(pactl list short source-outputs | cut -d$'\t' -f1)

# list sources and then pick one (type number)
pactl list short sources
read SOURCE_ID

pactl move-source-output "$SOURCE_OUTPUT_ID" "$SOURCE_ID"

# wait until recognizes
wait

cat shazam.txt && rm shazam.txt

then: alias mysongrec=/path/to/this_script.sh

I'm using songrec 0.3.2 version from pacman. Pipewire 0.3.63

darukutsu avatar Dec 24 '22 11:12 darukutsu