对话框流 - 导入错误:无法导入名称'AgentsClient'



我对对话流程是个新手。这是我正在使用的音频到文本的代码。我在谷歌上搜索了这个错误,但找不到解决办法。任何帮助都是感激的。谢谢你!

import os
import dialogflow_v2 as dialogflow
from dialogflow_v2 import AgentsClient
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = r"D:Resume buildinggcloudtstuff24Jan2020testing-302710-cc7fef4033ff.json"
project_id = '*******'
session_id = "ayesha"
audio_file_path = r'C:UsersayeshaDownloadssample - mp3 inserted.wav'
language_code = 'en'
def detect_intent_audio(project_id, session_id, audio_file_path, language_code):
"""Returns the result of detect intent with an audio file as input.
Using the same `session_id` between requests allows continuation
of the conversation."""
from google.cloud import dialogflow
session_client = dialogflow.SessionsClient()
# Note: hard coding audio_encoding and sample_rate_hertz for simplicity.
audio_encoding = dialogflow.AudioEncoding.AUDIO_ENCODING_LINEAR_16
sample_rate_hertz = 16000
session = session_client.session_path(project_id, session_id)
print("Session path: {}n".format(session))
with open(audio_file_path, "rb") as audio_file:
input_audio = audio_file.read()
audio_config = dialogflow.InputAudioConfig(
audio_encoding=audio_encoding,
language_code=language_code,
sample_rate_hertz=sample_rate_hertz,
)
query_input = dialogflow.QueryInput(audio_config=audio_config)
request = dialogflow.DetectIntentRequest(
session=session,
query_input=query_input,
input_audio=input_audio,
)
response = session_client.detect_intent(request=request)
print("=" * 20)
print("Query text: {}".format(response.query_result.query_text))
print(
"Detected intent: {} (confidence: {})n".format(
response.query_result.intent.display_name,
response.query_result.intent_detection_confidence,
)
)
print("Fulfillment text: {}n".format(response.query_result.fulfillment_text))

detect_intent_audio(project_id, session_id, audio_file_path, language_code)    dialogflow services.

我得到

importterror: cannot import name 'AgentsClient'

我直接从我已经在我的谷歌云上的项目创建我的json文件。我在对话流中创建了一个新项目,它成功了。

最新更新