def ProcessSwitch(switch): # Check that switch sounds are on switchsound = FileUtils.GetConfigValue("general", "ambientsound") if switchsound == 'on': soundClip = SoundClip.SoundClip() soundClip.Load(AirhornSoundDrive, 'S', switch) # Check that we have a sound config loaded if soundClip.fileSpec == "": tts.SayThis("No sound configured for switch " + switch) else: try: card = FileUtils.GetConfigValue("audio_ports", soundClip.audioPort) # Play the clip on a separate thread t = Switchplayerthread(card, soundClip.fileSpec, soundClip.volume, soundClip.balance) t.start() except: mod_MessageHandler.error( "Oops! Something went boom in AirhornPlayer ProcessSwitch." )
def play(soundClip): # Read the Ambientsounds configuration item ambientsound = FileUtils.GetConfigValue("general", "ambientsound") # Begin a loop while ambientsound == "on": # Calculate the amount of time to sleep this thread sleepTime = random.randrange(soundClip.minInterval, soundClip.maxInterval) # Sleep this thread time.sleep(sleepTime) # Play the configured Ambient sound try: card = FileUtils.GetConfigValue("audio_ports", soundClip.audioPort) # Play the clip on a separate thread t = Mythread(card, soundClip.fileSpec, soundClip.volume, soundClip.balance) t.start() except: tts.SayThis("Oops! Something went boom.") # Check to see if ambient sounds are still on ambientsound = FileUtils.GetConfigValue("general", "ambientsound") print ("Ambient sound " + str(soundClip.switchNumber) + " - finishing thread.")
def message(msg): print(msg) speak = FileUtils.GetConfigValue("general", "messagesound") if speak == "on": tts.SayThis(msg)
if AirhornSoundDrive == None: #wavplayer_alsaaudio.play('SystemSounds/needinfo.wav') mod_MessageHandler.error("No valid Airhorn sound drive found.") mod_MessageHandler.error( "Please initiate an Airhorn U.S.B. drive on your computer using the Airhorn Sound Manager utility." ) quit() # Load up all the ambient sounds and spin them up, each on its own thread. LoadAmbientSounds() # Default switch sounds to On FileUtils.SetConfigValue("general", "switchsound", "on") # Let the user know that we are up and ready for action mod_playwav.play(FileUtils.GetConfigValue("audio_ports", "1"), 'SystemSounds/gnarly.wav', 70, 0) #mod_MessageHandler.message("Airhorn audio environment controller is ready.") # Read the config to determine where we are getting our commands from if FileUtils.GetConfigValue("general", "consoleinput") == "on": while True: console_input = raw_input( 'Enter a switch number to play, n to listen to the network, or q to quit: ' ) if console_input == 'q' or console_input == 'Q': # turn off ambient sound processing. FileUtils.SetConfigValue("general", "ambientsound", "off") mod_MessageHandler.message("Ta Tah for now.") quit() #elif console_input == 'n' or console_input == 'N':
__author__ = 'mcalder' import mod_playwav import FileUtils # Test the TexToSpeech module #import TextToSpeech #TextToSpeech.SayThis('Piper down! We have a piper down over here! No, it\'s okay, he\'s just pissed.') # Here's a cheaty way to do multi-threading. USe a seperate subprocess for each thread using this code # Got it from here: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=23044&p=216151 # import subprocess # # def say(something, language='en', voice='f2'): # subprocess.call(['espeak', '-v%s+%s' % (language, voice), something]) # import FileUtils # airhornDrive = FileUtils.FindAirhornSoundDrive() # print airhornDrive #mod_playwav.play('sysdefault:CARD=DAC', '/media/marc/18FB-46B0/switch/1/Yard_Diesel_Fueling_Sequence.wav', 100,0) card = FileUtils.GetConfigValue("audio_ports", "1") print 'X' + card + 'X' assert card == 'sysdefault:CARD=DAC' print 'Card = ' + card mod_playwav.play(card, '/mnt/sdc1/switch/1/Engine_Bell_A.wav', 100, 0)