A simple tool allowing you to broadcast TTS (text to speech) on your local FM radio. Requires a raspberry pi.
(Uses douxxtech/piwave
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 gttsTo run this script, simply use this command while being in your home directory:
sudo ./piwave-env/bin/python3 tts-broadcast.pyand 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()