首先,我是一个使用dialogflow和Web服务的菜鸟。我正在尝试集成刚刚创建的dialogflow代理,并将其与本地计算机上的应用程序集成。我能够获得project_id和所有其他重要信息,但是无论我在哪里看,似乎都没有人谈论他们从哪里获得会话ID。这是我使用的音频到文本代码,是从api.ai github页面生成的:
import os
import dialogflow_v2 as dialogflow
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "My Google Credential"
project_id = 'project id'
session_id = "this i don't know where to get"
audio_file_path = 'my wave file directory name'
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 conversaion."""
session_client = dialogflow.SessionsClient()
# Note: hard coding audio_encoding and sample_rate_hertz for simplicity.
audio_encoding = dialogflow.enums.AudioEncoding.AUDIO_ENCODING_LINEAR_16
sample_rate_hertz = 44100
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.types.InputAudioConfig(
audio_encoding=audio_encoding, language_code=language_code,
sample_rate_hertz=sample_rate_hertz)
query_input = dialogflow.types.QueryInput(audio_config=audio_config)
response = session_client.detect_intent(
session=session, query_input=query_input,
input_audio=input_audio)
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)
我启用了webhook并将该webhook链接到了heroku,但是我仍然看不到该会话ID。有人可以帮我吗?
答案 0 :(得分:5)
在链接上, https://dialogflow.com/docs/reference/api-v2/rest/v2/projects.agent.sessions/detectIntent ,它在HTTP请求会话路径参数下指出 “由API调用者选择合适的会话ID。它可以是随机数或某种类型的用户标识符(最好是散列的)。会话ID的长度不得超过36个字节。”