def searchFood(term, limit=5, sort=2, radius_filter=8000): #sort = 2 is for highested rated params = { 'term': term, 'limit': limit, 'sort': sort, 'radius_filter': radius_filter, 'lang': 'fr' } result = client.search('Pittsburgh', **params) businesses = result.businesses names = "" for i in range(0, limit): if i == limit - 1: names += "and " + businesses[i].name else: names += businesses[i].name + ", " text_to_speech = TextToSpeechV1( username='******', password='******', x_watson_learning_opt_out=True) # Optional flag with open(join(dirname(__file__), 'resources/recommendations.wav'), 'wb') as audio_file: audio_file.write( text_to_speech.synthesize('Some good' + term + 'places are, ' + names, accept='audio/wav', voice="en-US_AllisonVoice")) audio = AudioFile('resources/recommendations.wav') audio.play() audio.close()
def processSpeech(name): ''' Asks name what they want to do and processes the speech into text. @param name string of name from face recognition @return extracted keyword from speech ''' if "Cho" in name: name = "Edward" elif "Wu" in name: name = "Johnny" elif "Deng" in name: name = "Michelle" elif "Liu" in name: name = "Vincent" # Initial greeting tts('Hello ' + name + '. \ What can I do for you today?', 'resources/greeting.wav') audio = AudioFile('resources/greeting.wav') audio.play() audio.close() # Wait for response print('waiting for response') recorder = Recorder('request.wav') recorder.record_to_file() print('transcribing') result = stt('request.wav') transcript = result['results'][0]['alternatives'][0]['transcript'] # Eating Section if "eat" in transcript: keyPhrase = 'I want to eat ' if keyPhrase in transcript: yelp_search.searchFood(transcript[len(keyPhrase)::]) return processSpeech(name) else: print('Did not say key phrase') return processSpeech(name) # Budget Section elif "budget" in transcript: watson_budget("Edward", "Friday") return processSpeech(name) elif "time" in transcript: if (datetime.datetime.time(datetime.datetime.now()) > datetime.time(4, 20, 0, 0) and datetime.datetime.time(datetime.datetime.now()) < datetime.time(4, 20, 59, 0)): tts("ay. lmao", 'resources/420.wav') audio = AudioFile('resources/420.wav') audio.play() audio.close() else: tts("The current time is " + datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y"), 'resources/time.wav') audio = AudioFile('resources/time.wav') audio.play() audio.close() # Default Case for not getting any proper key words else: return processSpeech(name)