def predict(speech_recognition=False, speech_synthesis=False): ''' Работа с обученной моделью seq2seq. 1. speech_recognition - включение распознавания речи с микрофона с помощью PocketSphinx 2. speech_synthesis - включение озвучивания ответов с помощью RHVoice ''' name_dataset = configure_file_names() ttt = TextToText(f_name_w2v_model=f_name_w2v_model, f_name_model=f_name_model, f_name_model_weights=f_name_model_weights) if speech_recognition: print('[i] Загрузка языковой модели для распознавания речи...') stt = SpeechToText('from_microphone', name_dataset) if speech_synthesis: print('[i] Загрузка синтезатора речи...') tts = TextToSpeech('anna') print() question = '' while (True): if speech_recognition: print('Слушаю...') question = stt.get() os.write(sys.stdout.fileno(), curses.tigetstr('cuu1')) print('Вы: ' + question) else: question = input('Вы: ') answer, lost_words = ttt.predict(question, True) print('\t=> %s' % answer) if len(lost_words) > 0: print('[w] Потерянные слова: ' + ', '.join(lost_words) + '\n') else: print() if speech_synthesis: tts.get(answer)