Vosk offline speech recognition and self learning conversation
def vosk_stt(lang, model): """ 獲取錄音訊息, 並傳回文字 """ global interrupted global lang global model if lang == '': lang = 'en' if model == '': model = 'model' r = sr.Recognizer() ## 進行錄音 r.pause_threshold = 0.5 ## 語音辨識間隔 with sr.Microphone() as source: ## 設定microphone try: audio = r.listen(source, timeout=5) ## 持續接收語音並存入audio except sr.WaitTimeoutError: print('沒有接收到語音') return except sr.UnknownValueError: