ibm watson 语音到文本

ibm watson speech to text

有人知道如何将此代码转换为 api 沃森语音转文本的密钥吗?

 <!-- STT default credentials -->
    
<string name="STTdefaultUsername">yyyyyyyy</string>

    <string name="STTdefaultPassword">xxxxxxxx</string>

    <string name="STTdefaultTokenFactory">https://stream.watsonplatform.net/speech-to-text/api</string>
    


<!-- TTS default credentials -->
    
<string name="TTSdefaultUsername">yyyyyyyy</string>
    
<string name="TTSdefaultPassword">xxxxxxx</string>
    
<string name="TTSdefaultTokenFactory">https://stream.watsonplatform.net/text-to-speech/api</string>
  

然后在下面调用

 private boolean initSTT() {
     // initialize the connection to the Watson STT service
     String username = getString(R.string.STTdefaultUsername);
     String password = getString(R.string.STTdefaultPassword);
     String tokenFactoryURL = getString(R.string.STTdefaultTokenFactory);
     String serviceURL = "wss://stream.watsonplatform.net/speech-to-text/api";
     SpeechConfiguration sConfig = new SpeechConfiguration(SpeechConfiguration.AUDIO_FORMAT_OGGOPUS);
     SpeechToText.sharedInstance().initWithContext(this.getHost(serviceURL), getActivity().getApplicationContext(), sConfig);
     // Basic Authentication
     SpeechToText.sharedInstance().setCredentials(username, password);
     SpeechToText.sharedInstance().setModel(getString(R.string.modelDefault));
     SpeechToText.sharedInstance().setDelegate(this);
     return true;
 }  

这可能会帮助您使用 IBM watson websocket 握手验证您自己。

要获得 authentication-token,您需要 运行 以下 cURL 命令。这可以在连接(websocket 握手)之前包含在您的程序中。

curl -k -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey={your apikey}" "https://iam.bluemix.net/identity/token"

您将获得令牌作为响应。

并在握手时使用此 token 进行身份验证。

下面给出了我如何使用 boost 库在我的 C++ 项目中使用它。

ws_.async_handshake_ex(host_, "/speech-to-text/api/v1/recognize",[](request_type& reqHead){reqHead.insert(http::field::authorization,"Bearer {my_token}");},std::bind( &session::on_handshake, shared_from_this(), std::placeholders::_1));

试试这个而不是你的 apikey。不要忘记添加 "Bearer"

关注此 link 了解更多详情 - https://console.bluemix.net/docs/services/watson/getting-started-iam.html

您可以尝试用您的语言做同样的事情。

Android SDK 可与 Java SDK primarily. The Java SDK handles most of the authentication and HTTP logic while the Android SDK just adds things on to get it to work on mobile devices. A deprecated link for it was posted above, so for reference, this 配合使用,您可以在其中找到 Android SDK。

Java SDK 自述文件是您可以找到有关入门的大部分信息的地方。对于这种情况,您可以在 this section.

中找到帮助

要将所有内容放在这里,如果您的资源中有 API 密钥,您可以执行以下操作:

SpeechToText service = new SpeechToText();
IamOptions options = new IamOptions.Builder()
  .apiKey(R.string.stt_api_key) // this is your API key
  .build();
service.setIamCredentials(options);

同样,您需要引入 Java SDK 作为它的依赖项。要添加到您的 Gradle 配置的最新版本是:

compile 'com.ibm.watson.developer_cloud:java-sdk:6.14.0'

SDK 将处理在后端进行正确的 API 调用,您现在应该能够使用该 service 对象进行经过身份验证的 API 调用。