def getSpeech(): # Record an audio file using sound.Recorder: recorder = sound.Recorder('speech.m4a') recorder.record() # Record for 3 seconds for i in range(3): sound.play_effect('game:Beep') time.sleep(1) # Stop recording recorder.stop() time.sleep(1) result = 'no speech detected' try: speechDetect = speech.recognize('speech.m4a') result = speechDetect[0][0] #print('=== Details ===') # print(result) #print('=== Transcription ===') # print(result[0][0]) except RuntimeError as e: print('Speech recognition failed: %s' % (e,)) sound.play_effect('game:Error') return result
def start(self, play=False): while True: self.file = tempfile.mkstemp('.m4a')[1] print(self.file) self._recorder = sound.Recorder(self.file) self._recorder.record(self.SECONDS) # loop clips wait_until(self.finished, self.SECONDS + 1, 0.1) self._stats() if play and self.DEBUG: print('Replaying...', ) player = sound.Player(self.file) player.play() print(player.duration) os.remove(self.file) #if threshold reached, call if self.louder_than(): if self.DEBUG: print('🚼 CALLING MUMMY !!! 🔔🔔🔔') else: self._call()
def anything_else(): import time, sound speech.say("Mr. {Name} is there anything else I may help you with?", "en-UK") time.sleep(3) rec = sound.Recorder("audio.m4a") rec.record() time.sleep(3) rec.stop() result = speech.recognize("audio.m4a")[0][0] if result == "Yes": speech.say("Oops that is the end of my code sir, but I did hear yes", "en-UK") elif result == "No": speech.say("That is the end of my code sir, but I did hear no.", "en-UK") else: speech.say("I did not hear a response, so I will assume you are ready for the day,", "en-UK")
def listen(): global command global index recorder = sound.Recorder('speech.m4a') while 'exit' not in command: speech.say('listening') print('listening') recorder.record() time.sleep(3) recorder.stop() try: text = speech.recognize('speech.m4a') [command, index] = stadardize_command(text[0][0], index) print(command) except: pass
def setup(self): t_path = os.path.join(tempfile.gettempdir(), 't.png') self.filename = os.path.abspath(t_path) data.writeToFile_atomically_(self.filename, True) frame = ui.Image(self.filename).resizable_image(0,0,255,255) texture = Texture(frame) self.img = SpriteNode(texture, position=self.size/2,parent=self) self.img.shader = Shader(acid_shader) r_path = os.path.join(tempfile.gettempdir(), 'r') self.r=[sound.Recorder(r_path) for i in range(2)] self.r_active = self.r[0] self.r_active.record() self.wave = 5 -abs(max(self.r_active.meters['average']))/10 self.img.shader.set_uniform('param', self.wave) self.img.effects_enabled = True
async def start(self, instance, value): duration, = self.duration.value rec = sound.Recorder('recorded.m4a') rec.record() print(f'Recording for {duration}...') await self.async_lib.sleep(duration) rec.stop() await self.async_lib.sleep(0.1) result = speech.recognize('recorded.m4a') if len(result): full_text, full_info = result[0] await self.text.write([full_text]) await self.confidence.write( [min(info['confidence'] for info in full_info)]) for info in full_info: print('@ {timestamp} {duration} sec' 'heard: {substring} ({confidence})' ''.format(**info)) else: await self.text.write([str(result)])
#for windows ONLY import speech import sound from random_word import RandomWords r = RandomWords() playing = True words = 0 inaccuracy = 0 for i in range(10): words += 1 Word = True word = r.get_random_word() while Word: speech.say(word, 'es_ES') r = sound.Recorder('audio.m4a') print("3") time.sleep(1) print("2") time.sleep(1) print("1") time.sleep(1) print(word) r.record(3) text = speech.recognize('audio.m4a', 'en')[0][0] if text == word: Word = False else: inaccuracy += 1 print("try again") print(inaccuracy / words)
# https://forum.omz-software.com/topic/3862/speech-sound-module-q-s/4 import speech, sound, time rec = sound.Recorder("audio.m4a") rec.record() time.sleep(3) rec.stop() result = speech.recognize("audio.m4a") print(result)
import ui # To implement a GUI interface import sound # to play sound files import time # to shorten the length of certain sound effects import os # to rename a file import asyncio # import wave # not sure yet what its capable of. # Voice X-formation functions from VXfunctions import voices2Emulate, originalVoices, XformedVoices, getWaveFile, determineFileName, playClickSound, waveViewTD path2_originalVoices = './waveFiles/originalVoices/' global_prevValues = {} # to store previous image values so that they may be reset # global objects so that playing and recording won't stop when button func. returns global_soundRecorderObj = sound.Recorder(path2_originalVoices + 'temporary.wav') global_soundPlayerObj = None # GUI functions ******************************************************************** # NOTE v['whatever'] are ui.View type objects!!!!! def textField_dataEntered(sender) : # want to get rid of keyboard at this point pass # not working correctly, do not call def restorePlayButton(): while True:
def main(): # initialize drink_status = False drunk_level = 0 bill = 0 while (drink_status == False): # display menu print("++++") print("Menu") print("") for drink in staff_action["menu"]["drink"].keys(): print(drink) print("++++") # take a order speech.say("ご注文をどうぞ!", 'ja-JP') time.sleep(1.8) recorder = sound.Recorder('speech.m4a') recorder.record() dialogs.alert('注文が終わったらボタンをタップしてください.', '', 'Finish', hide_cancel_button=True) recorder.stop() # replay voice = sound.Player('speech.m4a') voice.play() time.sleep(5.0) # recognize order try: result = speech.recognize('speech.m4a', 'ja-JP') except RuntimeError as e: print("recognition failed: %s" % (e, )) # order done hit = False for candidate in staff_action["menu"]["drink"].keys(): if candidate in result[0][0]: string = 'お待たせしました、' + candidate + 'です!' speech.say(string, 'ja-JP') print(string) # add bill and drunk_level bill += staff_action["menu"]["drink"][candidate]["price"] drunk_level += staff_action["menu"]["drink"][candidate]["alc"] hit = True break if not hit: string = "申し訳ありません、当店には取りあつかいがありません。" speech.say(string, 'ja-JP') print(string) # check drunk_level if (drunk_level >= drunk_threshold): string = "あ、お茶をお出ししますね。" speech.say(string, 'ja-JP') string = "お会計は" + str(bill) + "円です。お気をつけておかえりください。" speech.say(string, 'ja-JP') drink_status = True time.sleep(2.0)
def StartRec(btn): rec = sound.Recorder(SevedFName()) rec.record(10) btn.rec = rec btn.title = 'stop' btn.action = StopRec