Мои навыки программирования очень ограничены, поэтому я заранее извиняюсь.
Я пытаюсь получить намерение DialogFlow через потоковое аудио.Я тестирую его с помощью микрофона.
Я ссылался на следующие примеры кодов Google.
Потоковое аудио с микрофона для Google STT
НамерениеОбнаружение для Google DialogFlow
Оба работают нормально, но когда я пытаюсь объединить два примера кода, я получаю следующую ошибку:
No handlers could be found for logger "grpc._channel"
Traceback (most recent call last):
File "detect_intent_stream.py", line 181, in <module> detect_intent_stream(project_id, session_id, language_code)
File "detect_intent_stream.py", line 162, in detect_intent_stream for response in responses:
File "C:\Python27\lib\site-packages\google\api_core\grpc_helpers.py", line 83, in next six.raise_from(exceptions.from_grpc_error(exc), exc)
File "C:\Python27\lib\site-packages\six.py", line 737, in raise_from raise value
google.api_core.exceptions.Unknown: None Exception iterating requests!
Я искал решение, иЯ наткнулся на этот пост.Но я не уверен, как реализовать предложенное предложение.
Промежуточные результаты по использованию session_client.streaming_detect_intent ()
Ниже приведен код, который у меня есть на данный момент.
def detect_intent_stream(project_id, session_id, language_code):
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16
sample_rate_hertz = 8000
session_path = session_client.session_path(project_id, session_id)
def request_generator(audio_config):
query_input = dialogflow.types.QueryInput(audio_config=audio_config)
yield dialogflow.types.StreamingDetectIntentRequest(session=session_path, query_input=query_input, single_utterance=True)
with MicrophoneStream(RATE, CHUNK) as stream:
#while True:
#Temp condition
while dialogflow.types.StreamingRecognitionResult().is_final == False:
audio_generated = stream.generator()
#Temp condition
if not audio_generated:
break
yield dialogflow.types.StreamingDetectIntentRequest(input_audio=audio_generated)
audio_config = dialogflow.types.InputAudioConfig(audio_encoding=audio_encoding, language_code=language_code, sample_rate_hertz=sample_rate_hertz)
requests = request_generator(audio_config)
responses = session_client.streaming_detect_intent(requests)
print('=' * 20)
for response in responses:
print('Intermediate transcript: "{}".'.format(response.recognition_result.transcript)).encode('utf-8')
query_result = response.query_result
print('=' * 20)
print('Query text: {}'.format(query_result.query_text))
print('Detected intent: {} (confidence: {})\n'.format(
query_result.intent.display_name,
query_result.intent_detection_confidence))
print('Fulfillment text: {}\n'.format(
query_result.fulfillment_text))
Редактировать: я исправил свой ссылочный код.