Streaming audio to Raspberry Pi radio

2.2k views Asked by At

I'm using this guide to turn my Raspberry Pi into an FM transmitter. I can record audio, scp it over and then play it using the method described in the guide. My aim is to use a microphone on my main PC to stream audio over the network to the Pi, with will pipe it to the PiFm program.

I can't seem to pipe in an audio file at all, even locally on the Pi. Here is the prescribed method for playing a sound file using PiFm:

sudo python
>>> import PiFm
>>> PiFm.play_sound("sound.wav")

I've tried adding fileinput to the PiFm.py file using this method but when I try to give it a WAV file as an argument, or pipe it in, I get the following error:

pi@raspberrypi ~/radio $ sudo python PiFm.py sound.wav 
Traceback (most recent call last):
  File "PiFm.py", line 11, in <module>
    play_sound(line)
  File "PiFm.py", line 7, in play_sound
    call(["./pifm", filename])
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
TypeError: execv() arg 2 must contain only strings

Here is my PiFm.py file:

#!/usr/bin/python

from subprocess import call
import fileinput

def play_sound( filename ):
   call(["./pifm", filename])
   return

for line in fileinput.input():
    play_sound(line)
1

There are 1 answers

0
Prof. Falken On

Try:

PiFm.play_sound(u'sound.wav'.encode('utf8'))