Advertisement
jezzye13

AnnouncerTS-11vi

Jul 16th, 2024
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | Source Code | 0 0
  1. # Anouncer for TS-11vi radio
  2. # pip install gtts and python-vlc
  3. import time
  4. import vlc
  5. from gtts import gTTS
  6. import RPi.GPIO as GPIO
  7. from datetime import datetime
  8.  
  9. def main():
  10.     # Get text to say
  11.     now = datetime.now()
  12.  
  13.     mytext = "De datum van vandaag is" + now.strftime("%m/%d/%Y") + " en de tijd is " + now.strftime("%H:%M")
  14.  
  15.     # Relay 3
  16.     PTTreplayPin = 21
  17.  
  18.     language = 'nl'
  19.  
  20.     GPIO.setmode(GPIO.BCM)
  21.     GPIO.setup(PTTreplayPin, GPIO.OUT)
  22.     GPIO.output(PTTreplayPin, GPIO.HIGH)
  23.  
  24.     myobj = gTTS(text=mytext, lang=language, slow=False)
  25.  
  26.     myobj.save("audio.mp3")
  27.  
  28.     print("Tx")
  29.     # Turn on PTT
  30.     GPIO.output(PTTreplayPin, GPIO.LOW)
  31.  
  32.     # Wait one second
  33.     time.sleep(1)
  34.  
  35.     # Playing the converted file
  36.     player = vlc.MediaPlayer("audio.mp3")
  37.     player.play()
  38.  
  39.     # Wait a second
  40.     time.sleep(1)
  41.  
  42.     while(player.is_playing()):
  43.         if(player.is_playing() == 0):
  44.             # Wait a second
  45.             time.sleep(1)
  46.             # Turn off PTT
  47.             GPIO.output(PTTreplayPin, GPIO.HIGH)
  48.  
  49.  
  50.     GPIO.cleanup()
  51.     print("Done!")
  52.     exit()
  53.  
  54. if __name__ == "__main__":
  55.     main()  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement