Hacked Sox to work also using remote sinks and sources
See original GitHub issueSo this isn’t a bug as I’ve managed to get AlexaPi working but I had to make 1 minor code modification and want to share the info to test how robust my hack is and to maybe help others. Please point me in the right direction if here isn’t the right place for this.
CAUTION: I’m not a developer!
TL;DR
I amended line 46 in the AlexaPi/src/alexapi/playback_handlers/soxhandler.py
file from sox_cmd = ['sox', '-q', audio_file]
to sox_cmd = ['sox', '-q', audio_file, '-d']
The Detail New RPi3 user, running Raspbian jessie 8.0 with all stock packages. PulseAudio is running in System Mode, however, I have no directly connected sinks/speakers or sources/microphones attached to the RPi3. Instead, I use zeroconf (avahi) to share the audio devices of my ubuntu server with the RPi3 on my local network. So basically the RPi3 is connected via wifi and plays audio via the speakers which are physically connected to my server, same goes with the microphone to record. I had this all set up and working before I attempted AlexaPi.
For AlexaPi I just walked the path you guys laid out with the installation script but in addition I noted the alexapi user had its home directory set as /var/lib/AlexPi
and in here you have a .config/pulse
directory so I needed to put in their the PulseAudio security cookie from my server. After that the I amended the /etc/opt/AlexaPi/config.yaml
file with only the following changes…
input_device: "pulse"
playback_handler: "vlc"
output: ""
output_device: ""
Now, this all works but I had a strange issue with Alexa’s output where the playback clipped twice at the start of the output but then was fine for the remaining duration. So asking Alexa to “play my flash briefing” I noticed in debug there are about 3 or 4 separate play operations and this clipping/clicking at the front of each which was really annoying.
I quickly dived into the wiki e.g. here and tried all of the sensible-for-me suggestions i.e. installing the full vlc package but nothing resolved this. I then came across the playback_handler
setting in the config file and looked up this thread and so gave sox a try, however, I hit the same error message others in this thread have reported…
Error attempting play. sox FAIL sox: missing filename
Now the debug output helpfully includes the command used to wield sox so I gave this a try outside of AlexaPi to figure it out. sox -q /opt/AlexaPi/src/resources/alexayes.mp3 vol -6 dB pad 0 0
just fails at the command prompt and lists the command help text for sox, if this isn’t proof enough sox is installed I even checked it properly…
pi@blackpi:/var/lib/AlexaPi $ dpkg -l sox
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===================================-======================-======================-===========================================================================
ii sox 14.4.1-5 armhf Swiss army knife of sound processing
Reading the man page for sox it seems the sox devs include handly little sym-linked executables to make it simple for simpletons like me i.e. play and rec. These worked first time at the command prompt so this had to be something in the AlexaPi code. Anyways for me amending the sox command to
include a -d
directly following the filename worked…
So changing sox -q /opt/AlexaPi/src/resources/alexayes.mp3 vol -6 dB pad 0 0
to sox -q /opt/AlexaPi/src/resources/alexayes.mp3 -d vol -6 dB pad 0 0
Quoting the sox man page…
-d, --default-device This can be used in place of an input or output filename to specify that the default audio device (if one has been built into SoX) is to be used. This is akin to invoking rec or play (as described above).
To incorporate this into AlexaPi I did my best to understand all your wizardry and located the AlexaPi/src/alexapi/playback_handlers/soxhandler.py
file. Line 46 reads sox_cmd = ['sox', '-q', audio_file]
so I amended this to be sox_cmd = ['sox', '-q', audio_file, '-d']
. I was pretty surprised when it worked, sox now played back the audio and there is no clipping or clicking whatsoever!
I realise the audio aspect to AlexaPi is complex and that I don’t fully understand it so wanted to offer this up in case I’m heading for a wreck or whether just possibly its okay and useful to others.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@KillerKelvUK you must have
libsox-fmt-pulse
:Awesome!