1

API 文档可以在这里找到:https ://github.com/watson-developer-cloud/java-sdk

当我尝试使用该服务时,它会正确验证,然后在合成方法上失败。

 TextToSpeech tts_service = new TextToSpeech();
 tts_service.setUsernameAndPassword("<username>", "<password>");

 tts_service.synthesize("The cat sat on the mat", Voice.EN_LISA, "audio/ogg; codecs=opus");

错误的堆栈跟踪如下所示。我也尝试了不带语音和格式参数的合成方法(因为它有默认值),但是当我这样做时服务失败并出现相同的错误。

2015 年 11 月 25 日下午 4:58:55 com.ibm.watson.developer_cloud.service.WatsonService 执行严重: https ://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=The% 20cat%20sat%20on%20the%20mat&voice=en-US_LisaVoice&Accept=audio%2Fogg%3B%20codecs%3Dopus,状态:400,错误:不允许使用参数 [u'Accept']。2015 年 11 月 25 日下午 4:58:55 com.vaadin.server.DefaultErrorHandler doDefault SEVERE:com.ibm.watson.developer_cloud.service.BadRequestException:不允许使用参数 [u'Accept']。在 com.ibm.watson.developer_cloud.service.WatsonService.execute(WatsonService.java:128) 在 com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeech.synthesize(TextToSpeech.java:119)

我很感激这方面的一些帮助,并希望使用 java API 而不是 REST 调用。

谢谢。

4

1 回答 1

1

Java-SDK 正在发送Accept而不是accept(严重错误)。

在我们的下一个版本之前的解决方法是扩展TextToSpeech类并覆盖:

InputStream synthesize(final String text, final Voice voice, final String outputFormat)

例子:

public class TextToSpeechHotFix extends TextToSpeech {

  @Override
  public InputStream synthesize(final String text, final Voice voice, final String outputFormat) {
    final RequestBuilder request = RequestBuilder.get(PATH_SYNTHESIZE);
    request.withQuery(TEXT, text);
    request.withQuery(VOICE, voice.getName());

    if (outputFormat != null && !outputFormat.startsWith("audio/"))
      throw new IllegalArgumentException(
          "format needs to be an audio mime type, for example: audio/wav or audio/ogg; codecs=opus");

    request.withQuery(ACCEPT, outputFormat != null ? outputFormat : HttpMediaType.AUDIO_WAV);

    final Response response = execute(request.build());
    return ResponseUtil.getInputStream(response);
  }
}
于 2015-11-27T05:03:17.473 回答