question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hacked Sox to work also using remote sinks and sources

See original GitHub issue

So 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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
EmerickHcommented, Jun 14, 2017

@KillerKelvUK you must have libsox-fmt-pulse:

sudo apt-get install libsox-fmt-pulse
0reactions
reneklimentcommented, Jun 14, 2017

Awesome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

XSS (Cross Site Scripting) - HackTricks
You could exploit a DOM XSS, pay attention how your input is controlled and if your controlled input is used by any sink....
Read more >
PulseAudio under the hood - Victor Gaydov
PulseAudio may automatically create a pair of virtual source and sink for every remote sound card exported by every PulseAudio server in the ......
Read more >
Be Afraid! Hackers Can Control Your Car, TV and Home
Sure, it's great that you can control your alarms, locks and remote notification through your smartphone and check your security cameras online.
Read more >
0xdf hacks stuff | CTF solutions, malware analysis, home lab ...
The source for the site and the sandbox is also downloadable. ... and use that as an SSRF to get execution through a...
Read more >
how to get remote access to your hacking targets ... - YouTube
Protect your grandma from RATS: https://bit.ly/bdnetworkchuck (try Bitdefender for FREE for 120 days) Links and Guide: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found