Pi Transmit Voice to FM Radio no extra hardware required


34 posts   Page 1 of 2   1, 2
by codyrigney92 » Wed Feb 13, 2013 5:55 am
I figured out how to broadcast your voice through the radio using the raspberry pi, i.e. speak through a mic and tune your radio to a frequency to hear it, in real time!

It's actually quite simple.
First, follow the instructions here to get the FM transmitter setup on your raspberry pi. This transmits .wav files through a specified frequency and requires no extra hardware besides an optional antenna! These guys that did this are brilliant, and it's open source! (This link is a cached version because the original site is down).
http://webcache.googleusercontent.com/search?q=cache:2sSuOAJQhN4J:www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter+raspberry+pi+fm+transmitter&cd=1&hl=en&ct=clnk&gl=us

Second, you need the ALSA sound library installed which most of you should already have this. The executable out of this we will use is 'arecord'.

Plug in your mic and attach an antenna to GPIO4 if desired.

Then here is the command you will use to start the broadcast. Each piece will be explained. Note that this command may need modified to work for your mic, just keep reading.
Code: Select all
arecord -fS16_LE -r 22050 -Dplughw:1,0 - | sudo ./pifm - 100.1 22050


Alright so:
Code: Select all
arecord

Program we are using to record audio.
---------------------------------------------------------

Code: Select all
-fS16_LE

Output 16-bit data. Needed this way for PiFM to read it.
---------------------------------------------------------

Code: Select all
-r 22050

This specifies sampling rate to output recording. 22,050 is a good balance for speed and quality.
---------------------------------------------------------

Code: Select all
-Dplughw:1,0

This is where you may need to modify. The '1' specifies card number and '0' is the device number I think. To find this out for your device, use
Code: Select all
arecord -l
to see all of the audio devices connected.
---------------------------------------------------------

Code: Select all
-

Here it means to print output to standard out.
---------------------------------------------------------

Code: Select all
|

Pipe the standard out from previous command to next command's standard input.
---------------------------------------------------------

Code: Select all
sudo ./pifm - 100.1 22050

This is explained in the link at the top. '-' means use standard input for "file"(Remember we piped it). '100.1' is the frequency in Mhz to transmit and '22050' is the sampling rate of the input. Actually if you change the sampling rate lower it will output a low pitch sound and higher will do a high pitch sound, kind of a voice changer.

If you did everything right, after you run the command you should be able to tune your radio to 100.1 Mhz and hear yourself talking through the mic!

Good luck! And don't amplify your signal or you could risk getting a fine from the FCC or whatever the agency is for your country!
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by codyrigney92 » Wed Feb 13, 2013 11:07 pm
For those who need the audio capture program:
Code: Select all
sudo apt-get install libasound2

I think. If that doesn't work try libasound2-dev.
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by mikerr » Thu Feb 14, 2013 10:09 pm
Link to other thread on this in December:
viewtopic.php?f=37&t=25301
Got a Pi Camera? View it in my android app - Raspicam Remote ! No software required on the pi
User avatar
Posts: 1216
Joined: Thu Jan 12, 2012 12:46 pm
Location: NorthWest, UK
by codyrigney92 » Fri Feb 15, 2013 12:39 am
mikerr wrote:Link to other thread on this in December:
viewtopic.php?f=37&t=25301

I saw that post and didn't see anything about using the mic with it so I thought I would share my findings.

By the way do you know if its possible to hit multiple frequencies at once? I have a theory but doubt it would work if I even knew how to program it.
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by redhawk » Fri Feb 15, 2013 1:04 am
The Pi transmitter uses a square wave generator this by design exhibits a lot of harmonic distortion which appears as multiple transmissions around the FM band.
Unfortunately there are several problems with this type of modulation:
- the positions of the extra stations (harmonics) are virtually impossible to control and may not be possible get a accurate lock with a digital turner (analogue only).
- the audio loudness varies greatly for each harmonic when tuning away from the initial transmission frequency.
- the transmission power decreases for each harmonic when tuning away from the initial transmission frequency.

Richard S.
User avatar
Posts: 3474
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1
by felix3008 » Sat Feb 16, 2013 4:41 pm
Wow, this Transmitter is amazing...

I use the transmitter with the vlc media player, which allows me to transmit almost anything (internet radio stream, mic, music from my NAS-Drive).

How i did it:
You need:
-VLC Media player ("sudo apt-get install vlc")
-PiFM (http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter)
Make a FIFO-File:
Code: Select all
mkfifo /tmp/radio


Open two terminals
Terminal 1:
Code: Select all
 vlc YOUR_FILE_STREAM_OR_DEVICE_HERE vlc://quit --intf=dummy --no-sout -smem-time-sync --sout='#transcode{acodec=s16l,ab=32,samplerate=44100,channels=1}:std{access=file,mux=dummy,dst=-}' > /tmp/radio


Terminal 2 (cd into the PiFM dir):
Code: Select all
sudo ./pifm /tmp/radio YOUR_FREQ 44100

----------------
I used an old audio signal amplifier and an DVB-T antenna, wired to GPIO 4.
Signal is pretty good within 1.5 MILES, which is a pretty long distance. (I do not know if that is even legal?!?!)
-----------------
Possible Uses:
-wireless Speaker system (as almost all FM Devices have no sound delay)
-local radio station for your neighborhood (legal issues)
-Broadcast current readings from sensors (In conjunction with espeak)
-Probably more...


Felix3008
User avatar
Posts: 34
Joined: Sun Dec 30, 2012 2:04 am
by BirchJD » Sat Feb 16, 2013 5:20 pm
I recommend you do not do this using high power. You need a license to transmit on all frequencies except a very narrow band which you can transmit on with very low power without a license.

If you interfere with emergency frequencies, Police, Ambulance, Fire or aviation, you will be in serious trouble; if you intended to or not. And you will get into trouble transmitting on other frequencies without a license and with uncalibrated and un-certified equipment.
http://www.newsdownload.co.uk/
User avatar
Posts: 94
Joined: Tue Nov 13, 2012 7:43 pm
by felix3008 » Sat Feb 16, 2013 9:04 pm
Yeah, i know that i would have legal issues if i let it run at that power level.
I have stripped down the power on the amplifier to a minimum now and now my pi transmits in the range of 40 meters which should be ok.
Thanks for the heads up though. ;)

Felix3008
User avatar
Posts: 34
Joined: Sun Dec 30, 2012 2:04 am
by codyrigney92 » Sun Feb 17, 2013 2:36 am
@felix3008
Awesome thanks for that. Would you be able to point me to the amplifier you used? For learning purposes so if there is a tutorial or something that would be helpful too. Thanks!
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by italio » Fri Feb 22, 2013 5:31 am
codyrigney92 wrote:Then here is the command you will use to start the broadcast. Each piece will be explained. Note that this command may need modified to work for your mic, just keep reading.
Code: Select all
arecord -fS16_LE -r 22050 -Dplughw:1,0 - | sudo ./pifm - 100.1 22050



Hello Everyone!
I love the idea of broadcasting the microphone through PiFm, however, when I run the code above exactly as stated, the broadcast starts and I get these messages:
Code: Select all
Recording WAVE '-' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Setting up modulation:100.099998 Mhz / 20459 @ 22050.00000
Now broadcasting: -

Shutting Down


The problem is that while it appears to work, the shutting down message appears immediately after I run the command. That is to say, it says now broadcasting and then shuts down within the same second and simply will not broadcast.

Does anyone have a solution they could suggest?
Thank you so much!
Posts: 2
Joined: Fri Feb 22, 2013 5:24 am
by codyrigney92 » Sat Feb 23, 2013 7:03 am
That's odd. What do you get if you do?
Code: Select all
arecord -l


Maybe your audio device is on a different card than mine.
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by nick258 » Sat Feb 23, 2013 9:04 pm
I have been trying to figure this out for the past couple of days...

Whenever I try transmit a song (I've been trying with sample song, so it SHOULD work) it instead transmits a sine wave / square wave tone for several seconds which then breaks up into heavy irregular static. when I turn up the volume on my speakers that I have plugged into my pi, I can here the same noises that are coming out of my radio.

Has this happened to anybody else? Does anybody have a possible solution?

I'm fairly certain this is being caused by a problem with PiFm. Also, when I transmit silence, it makes that same tone, but when I shut off the transmission, THEN it becomes silent. I am baffled.
Posts: 4
Joined: Sat Feb 23, 2013 8:47 pm
by nick258 » Sun Feb 24, 2013 4:16 am
Wow. Problem resolved. I just messed around with the sample rates and spammed the arecord command a bunch of times until my system crashed and the sampling rates were back to 22050. Now it works perfectly.
Posts: 4
Joined: Sat Feb 23, 2013 8:47 pm
by Grumpy Mike » Sun Feb 24, 2013 9:56 pm
felix3008 wrote:Yeah, i know that i would have legal issues if i let it run at that power level.
I have stripped down the power on the amplifier to a minimum now and now my pi transmits in the range of 40 meters which should be ok.
Felix3008

In what way do you think that?
Transmitting even at that range without a license is illegal.
User avatar
Posts: 783
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by tonyhughes » Sun Feb 24, 2013 10:03 pm
"PiRate" radio!

MUHAHAHAHAHA

Sorry.
Baked Linux Mod http://www.geek101.co.nz/bakedlinuxmod

Easy install of Drupal, Wordpress, RazorCMS, Chyrp, Apache, Nginx, Lighttpd, firewall, Webmin, VNC, RDP, FTP servers, mailservers, MySQL, SQLite, Transmission and more...

tall.co.nz/webcam.jpg
User avatar
Posts: 931
Joined: Wed Dec 26, 2012 3:46 am
by redhawk » Mon Feb 25, 2013 1:10 am
Actually the rules for license free FM transmitters is rather confusing to say the least, Ofcom states that output power must not exceed 50nW e.r.p. but just how far does this go distance wise.
Funnily enough I actually contact Ofcom not so long about the lack of transparency in this area unfortunately their response wasn't particular helpful.
Their official docs - http://www.google.co.uk/url?q=http://st ... IR2030.pdf

Legal purchased transmitters should carry the CE mark, the Pi is not a CE certified device for FM broadcasting so no matter how far or small your range is it's technically illegal to use.
The fact that the Pi can transmit harmonics outside the regular FM band is also a cause for concern since you could be unwittingly interfere with aviation communications 118MHz - 135MHz (Air band).
Proving you keep your range within 10 meters then I think most authorities would turn a blind eye to any broadcasting activity.

Just out of curiosity does anyone know how far 50nW e.r.p. could travel??

Richard S.
User avatar
Posts: 3474
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1
by W9RAN » Thu Mar 28, 2013 4:42 am
Thanks for this - but one question: where do you plug the mic in ;-)
Assume you've added a USB soundcard and I'll try that but having the answer in the thread would be good for posterity.

I've recompiled pifm with reduced deviation but it's still over 20KHz - anyone messed around with how to make it narrowband FM?

Bob
Posts: 19
Joined: Wed Feb 08, 2012 10:39 pm
by codyrigney92 » Fri Mar 29, 2013 10:14 pm
I just plugged my mic in to USB. I don't think the headphone jack doubles as a mic jack.
Posts: 58
Joined: Fri Dec 14, 2012 2:04 am
by jboolean » Sat Jul 06, 2013 8:03 pm
This looks insanely cool, but I can't get it to work. When I try the CPU-based version (http://www.icrobotics.co.uk/wiki/index. ... ransmitter) broadcasts a solid tone. I'm using the included wav file, and I turned off overclocking. Using the same file (or another file I made) with the DMA version from GitHub I get
Virtual memory mapped at 0xb6d48000
Failed to open .wav file
Posts: 1
Joined: Sat Jul 06, 2013 7:06 pm
by Obsidianjaguar » Mon Jul 15, 2013 10:04 pm
Hi guys ,
I have only had my Pi a few days now , and this project intrests me greatly ...
Sorry if its annoying but I have little to no experince with programming, so seeking help ...
My idea for this would be Ideally a USB headphone/Mic that I could wear... And broadcast in real time ..
If that wasnt Possible , then just a simple 3 Second loop of audio .. .
This should then somehow be able to cycle through a range of FM frequncies ... Not that I would do this , but can you imagine if I were driving down the road and some A**hole pulled out in front of me , then a loud " THANK YOU FOR ALMOST KILLING ME" came across his radio ,regardless of what station he was on :)
K
Posts: 1
Joined: Mon Jul 15, 2013 9:33 pm
by TheWalkingCactus » Wed Aug 21, 2013 5:52 pm
Firstly, THIS IS AWESOME! When I run it, I have very little latency, it's amazing what the pi can do! However, I am experiencing something weird. The latency slowly increases, and every now and then I get an error saying:
Code: Select all
overrun!!! (at least x.xxx ms long)
and the sound jumps ahead a bit.

I'm a bit confused as to what's happening, but I think it's the piFM not keeping up, so there's a buffer overflow/overrun of sound between the two programs.

It's super annoying/distracting, so I tried changing the sampling rate to 20000 on both piFM and arecord. When I did that, no sound was transmitted at all.

Are there only certain sampling rates that piFM works with? And is there a good way of fixing this problem?

Thanks in advance
Posts: 15
Joined: Fri Mar 29, 2013 7:53 pm
by jomonkainakary » Mon Sep 16, 2013 6:09 pm
hi all..
what i am trying to create is a FM repeater. So the idea would be to connect a RTL-SDR dongle to Rasp pi over USB and receive a WFM/NFM signal through it and Pipe it to PiFm project. i tried below command and failed. Please pardon me if i am doing true dumbest thing. I am just a self taught linux starter.

sudo rtl_fm -f 100.3e6 -W -s 200000 -r 22050 - | sudo ./pifm - 90.1 22050

sudo: ./pifm: command not found
Found 1 device(s):
0: Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Oversampling input by: 2x.
Oversampling output by: 4x.
Buffer size: 5.12ms
Tuned to 100716000 Hz.
Sampling at 1600000 Hz.
Output at 22050 Hz.
Tuner gain set to automatic.
Signal caught, exiting!

User cancel, exiting...



Is it possible to do this correctly...

Thanks in advance...
Posts: 2
Joined: Mon Sep 16, 2013 5:59 pm
by jomonkainakary » Fri Sep 20, 2013 3:17 am
jomonkainakary wrote:hi all..
what i am trying to create is a FM repeater. So the idea would be to connect a RTL-SDR dongle to Rasp pi over USB and receive a WFM/NFM signal through it and Pipe it to PiFm project. i tried below command and failed. Please pardon me if i am doing true dumbest thing. I am just a self taught linux starter.

sudo rtl_fm -f 100.3e6 -W -s 200000 -r 22050 - | sudo ./pifm - 90.1 22050

sudo: ./pifm: command not found
Found 1 device(s):
0: Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Oversampling input by: 2x.
Oversampling output by: 4x.
Buffer size: 5.12ms
Tuned to 100716000 Hz.
Sampling at 1600000 Hz.
Output at 22050 Hz.
Tuner gain set to automatic.
Signal caught, exiting!

User cancel, exiting...



Is it possible to do this correctly...

Thanks in advance...



the error was removed by deleting the pifm file and recompiling once again with the same name... but nothing else noise was heard at my receiver tuned to 90.1 Mhz.
Posts: 2
Joined: Mon Sep 16, 2013 5:59 pm
by vnitinv » Fri Oct 18, 2013 10:20 am
Can we also save the audio from mic to a audio file at the same time. (Can we use tee command for the same, if then how we need to call it)
Posts: 1
Joined: Fri Oct 18, 2013 10:18 am
by TheMacMini09 » Sun Nov 03, 2013 2:33 pm
Thanks so much for this! However, would it be possible to transmit from the microphone and a .wav file at the same time? That would be amazing! If not, ah well. And by the way, a 30 cm wire has a range of an entire property (150x150m) without any static! Amazing what a Pi can do!
Posts: 1
Joined: Sun Nov 03, 2013 2:24 pm