IBM沃森语音到文本

问题描述 投票:-1回答:2

任何人都知道如何把这个代码转换成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;
 }  
android ibm-watson speech-to-text
2个回答
0
投票

Android的SDK是建立与Java SDK主要工作。在Java SDK处理大部分的认证和HTTP逻辑而Android SDK只是增加了对事物得到它在移动设备上运行。不推荐的链接,它被张贴以上,所以对于参考,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,使作为这个依赖。最新版本添加到您的摇篮配置是:

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

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


0
投票

这可能会帮助你对自己与IBM沃森的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为您的身份验证。

下面给出了我如何用它为我用C ++项目使用Boost库。

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。不要忘了加上“承载”

请点击此链接了解详情 - https://console.bluemix.net/docs/services/watson/getting-started-iam.html

您可以尝试在你的语言做同样的。

© www.soinside.com 2019 - 2024. All rights reserved.