Skip to content

Instantly share code, notes, and snippets.

@douxxtech
Created August 21, 2025 18:59
Show Gist options
  • Select an option

  • Save douxxtech/fdb510c7345fc90b25c0d53bf80f346e to your computer and use it in GitHub Desktop.

Select an option

Save douxxtech/fdb510c7345fc90b25c0d53bf80f346e to your computer and use it in GitHub Desktop.
A simple python script to broadcast text (TTS) on FM radio with a raspberry pi !

TTS Broadcaster

A simple tool allowing you to broadcast TTS (text to speech) on your local FM radio. Requires a raspberry pi.
(Uses douxxtech/piwave

Setup

Run these commands to setup your environment and install the nessesarry modules:

curl -sL https://setup.piwave.xyz/ | sudo bash
python3 -m venv ~/piwave-env

nano tts-broadcast.py
[PASTE THE CODE AT THE BOTTOM OF THIS GIST AND EXIT (^K -> y)]
~/piwave-env/bin/pip install git+https://github.com/douxxtech/piwave.git pydub gtts

Running

To run this script, simply use this command while being in your home directory:

sudo ./piwave-env/bin/python3 tts-broadcast.py

and then follow the instructions.

Tip

If you want more range, stick a wire on the GPIO 4 pin

tts-broadcast.py:

from gtts import gTTS
from piwave import PiWave
from pydub import AudioSegment
import os
import sys

wav_file = sys.argv[1] if len(sys.argv) > 1 else 'tts.wav'

def tts(text, wav_file):
      mp3_file = "tts.mp3"
      tts = gTTS(text=text, lang="en", slow=False)
      tts.save(mp3_file)
      sound = AudioSegment.from_mp3(mp3_file)
      sound.export(wav_file, format="wav")
      os.remove(mp3_file)

def main():
      
      print("=" * 50)
      print("Text Broadcast by https://douxx.tech")
      print("""You need PiWave and a raspberry pi with root
access to run this tool !""")
      
      try:
            while True:
                  print("=" * 50)
                  text = input("Text to broadcast: ").strip()
                  if not text:
                        print("No text entered, skipping...\n")
                        continue

                  try:
                        freq = float(input("Frequency to broadcast (MHz): "))
                  except ValueError:
                        print("Invalid frequency, please enter a number.\n")
                        continue

                  tts(text, wav_file)
                  pw = PiWave(silent=True, frequency=freq)

                  print("=" * 50)
                  print("Ready to play!")
                  print(f"Frequency : {freq} MHz")
                  print(f"Text      : {text}")
                  print(f"WAV file  : {os.path.abspath(wav_file)}")
                  print("=" * 50)

                  pw.send([wav_file])
                  print("Playing!\n")

      except KeyboardInterrupt:
            print("\nStopped by user.")
      finally:
            if os.path.exists(wav_file):
                  os.remove(wav_file)
                  print("Cleanup done. Exiting...")

if __name__ == "__main__":
      main()

Made by Douxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment