使用Java API时,文字转语音功能无效

时间:2018-07-30 01:51:29

标签: dialogflow

因此,我启用了文本语音转换功能,并启用了“启用beta功能和API”。在DialogFlow网页上,您可以在其中添加意图并对其进行测试,该功能正在运行,并且我得到了一个小的音频控件,在其中可以听到与完整文本相对应的音频。

但是,当我尝试通过Java API获取音频时,却听不到。下面的代码将产生以下输出:

>2018-07-30 02:26:53 mmcsrv.agent.SpeechIntentDetector: response_id
>
2018-07-30 02:26:53 mmcsrv.agent.SpeechIntentDetector: query_result
> 
2018-07-30 02:26:53 mmcsrv.agent.SpeechIntentDetector: webhook_status

我希望在那里找到output_audio字段,但是没有,所以音频在哪里?

此模块的我的Maven:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-dialogflow</artifactId>
    <version>0.53.0-alpha</version> 
</dependency>

我尝试使用0.55.1-alpha,但Maven表示它不存在。不确定是否使用最新版本是否会很重要。

有人可以帮助我吗?如果无法正常工作,则必须将文本发送回Google Cloud文本到语音转换,我猜这将比在Dialogflow响应中保留音频数据花费更多的时间。

谢谢。

//为简洁起见,省略了详细信息...

// Build the DetectIntentRequest
DetectIntentRequest request = DetectIntentRequest.newBuilder()
          .setSession(session.toString())
          .setQueryInput(queryInput)
          .setInputAudio(wav)
          .build();

// Performs the detect intent request
DetectIntentResponse resp = sessionsClient.detectIntent(request);

List<FieldDescriptor> fields = resp.getDescriptorForType().getFields();

for (FieldDescriptor field : fields )
        log.trace(field.getName());

1 个答案:

答案 0 :(得分:0)

要回答我自己的问题,

Dialogflow确实会发送音频,但是您需要正确的protobuffer代理才能获取音频。如果您像我一样使用Maven,则工件google-cloud-dialogflow的0.53.0-alpha版本会提取proto-google-cloud-dialogflow-v2beta1的0.18.0版,该版本的代理尚未包含文本到语音支持。

您需要通过将此代码段添加到pom文件中来添加0.20.1或更高版本:

<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-dialogflow-v2beta1</artifactId>
<version>0.20.1</version>

完成此操作后,类DetectIntentResponse将具有方法getOutputAudio(),该方法将为您提供音频数据。

我现在正在工作。

相关问题