0

I have a simple code that I want to execute that links my raspberry pi4 to a bluetooth speaker. It works as it is, but when I link it to a a subprocess call, there is no sound.

#!/usr/bin/python3

from pydub import AudioSegment
from pydub.playback import play

sound = AudioSegment.from_wav('mywavfile.wav')
play(sound)

The stdlog does not show any errors and its as if it played normally but no sound came out.

Not sure what is wrong.

k3nz3n
  • 1
  • What does the `subprocess` command look like you are using? Also, what happens if you use that above lines of code rather than calling a `subprocess` in your other code? – ukBaz Aug 31 '21 at 06:52
  • Im simplfying but in the main script, the code used is subprocess.call(['sudo', 'python', 'playsound.py']). The log shows it plays the file perfectly, just minus the sound. If I incorporated the pydub code in the main script, the speaker plays without a hitch. – k3nz3n Aug 31 '21 at 12:10
  • Btw are you the one that created that long 'ranting bluetooth blog post'? I recall your nickname being familiar. If so awesome! I followed tip 3.2 from that post but to no avail. – k3nz3n Aug 31 '21 at 12:14
  • "the speaker plays without a hitch" Does that mean you have it working now? And the long blog post you are referring to... is this this one? https://raspberrypi.stackexchange.com/a/116843/121848 – ukBaz Aug 31 '21 at 13:04
  • 'without a hitch' meaning if I use this code in my main python script, it plays well. If I use a subprocess to call this function from another script, it doesn't play - no errors and the log looks like it played the sound file. Still unable to get it played when using subprocess. Yes yes, that is the link :) Thanks for linking. – k3nz3n Sep 04 '21 at 06:40
  • Calling a Python script with a subprocess from a Python script feels slightly wrong. The [pydub library](https://github.com/jiaaro/pydub/blob/7b0d27a4eb7246324601ff1a120397eeddfa3ee5/pydub/playback.py#L16) is then calling a subprocess. So you have a Python script calling a subprocess calling a Python script calling a subprocess. If you don't want to call pydub directly in your main Python script, why not make your code above a function so you can import that to your main script and call it as a Python function and avoid the subprocess call? – ukBaz Sep 04 '21 at 07:16

0 Answers0