def run(self): logger.debug('%s SpeechToTextThread started with %s', self.name, type(self.audio_stream)) self.api = SpeechToText(audio_data=self.audio_stream, content_type=self.audio_type, access_token=self.access_token, headers=None, url=config.URL_SPEECH, producer=self.producer) self.api.post()
class SpeechToTextThread(threading.Thread): """Execute speech to text call in a thread.""" def __init__(self, audio_stream, access_token, audio_type, producer): threading.Thread.__init__(self, name="SpeechToTextThread") self.finished = threading.Event() self.access_token = access_token self.audio_type = audio_type self.producer = producer self.api = None self.audio_stream = audio_stream self.chunk_counter = 0 def run(self): logger.debug('%s SpeechToTextThread started with %s', self.name, type(self.audio_stream)) self.api = SpeechToText(audio_data=self.audio_stream, content_type=self.audio_type, access_token=self.access_token, headers=None, url=config.URL_SPEECH, producer=self.producer) self.api.post() def stop (self): self.finished.set() self.join()
def main(): nao("Mon nom é NAO. Je répondrai à vos questions sur la MIAGE de Nanterre Université. Pour quitter, dites Bye" ) nao("Pour choisir un thème,dites Menu") global themeLoaded global sent_tokens themeLoaded = 0 navigator = Navigator() while (True): user_response = st.conversion() printUser(user_response) if (navigator.indirect(user_response) == "Invalid" and themeLoaded == 1): nao(response(user_response)) sent_tokens.remove(user_response)
def menu(self): nao(MENU_TEXTS) user_response = st.conversion() printUser(user_response) self.indirect(user_response)
#on ne garde que les 2 dernières valeurs : req_tfidf = flat[-2] if (req_tfidf == 0): NAO_response = NAO_response + "Désolé ! Je n'ai pas compris." return NAO_response else: NAO_response = NAO_response + sent_tokens[idx] return NAO_response flag = True print( "NAO: Mon nom est NAO. Je répondrai à vos questions sur les ChatBots. Pour quitter, tapez Bye!" ) while (flag == True): user_response = st.conversion() user_response = user_response.lower() if (user_response != 'bye'): if (user_response == 'merci' or user_response == 'merci beaucoup'): flag = False print("NAO: Avec plaisir...") else: if (greeting(user_response) != None): print("NAO: " + greeting(user_response)) else: print("NAO: ", end="") print(response(user_response)) sent_tokens.remove(user_response) else: flag = False print("NAO: Bye bye ! A bientot !")
#-*- coding:utf-8 -*- from command import CheckCommand from speech import MakeAudio, SpeechToText from os import remove from os.path import isfile from keyboard import read_hotkey if __name__ == "__main__": print("음성인식을 하려면 Ctrl+Shift 를 눌러주세요.") while True: try: rk = read_hotkey(suppress=False) if rk == 'ctrl+shift': print("10초간 인식합니다~") MakeAudio() print("10초간 인식 완료~") text = SpeechToText() CheckCommand(Text=text) except: print("에러 발생~") break finally: if isfile('sirius_cmd.wav'): remove('sirius_cmd.wav')