Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Anouncer for TS-11vi radio
- # pip install gtts and python-vlc
- import time
- import vlc
- from gtts import gTTS
- import RPi.GPIO as GPIO
- from datetime import datetime
- def main():
- # Get text to say
- now = datetime.now()
- mytext = "De datum van vandaag is" + now.strftime("%m/%d/%Y") + " en de tijd is " + now.strftime("%H:%M")
- # Relay 3
- PTTreplayPin = 21
- language = 'nl'
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(PTTreplayPin, GPIO.OUT)
- GPIO.output(PTTreplayPin, GPIO.HIGH)
- myobj = gTTS(text=mytext, lang=language, slow=False)
- myobj.save("audio.mp3")
- print("Tx")
- # Turn on PTT
- GPIO.output(PTTreplayPin, GPIO.LOW)
- # Wait one second
- time.sleep(1)
- # Playing the converted file
- player = vlc.MediaPlayer("audio.mp3")
- player.play()
- # Wait a second
- time.sleep(1)
- while(player.is_playing()):
- if(player.is_playing() == 0):
- # Wait a second
- time.sleep(1)
- # Turn off PTT
- GPIO.output(PTTreplayPin, GPIO.HIGH)
- GPIO.cleanup()
- print("Done!")
- exit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement