gpt4 book ai didi

java - 如何使用Azure认知系统?

转载 作者:行者123 更新时间:2023-12-02 06:20:16 27 4
gpt4 key购买 nike

我正在尝试将我的 Android 应用连接到 Azure 语音识别认知系统。

我使用了很多方法,但每次我在“RUN”中得到null

第一次,我使用了下面的代码。

第二次,我从 Github 下载了库,但得到了相同的输出。

package com.example.api;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.net.URI;


public class MainActivity extends AppCompatActivity {
Button bb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bb=(Button)findViewById(R.id.bb);
bb.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View v) {
HttpClient httpclient = HttpClients.createDefault();

try
{
URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles");
/*AsyncHttpClient client = new AsyncHttpClient();
client.post()
"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles",
new AsyncHttpResponseHandler() {}*/


URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "application/json");
request.setHeader("Ocp-Apim-Subscription-Key", getString(R.string.record));


// Request body
StringEntity reqEntity = new StringEntity(getString(R.string.loc));
request.setEntity(reqEntity);


HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();

if (entity != null)
{
Log.i("",EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
});
}
}

list :

   <uses-permission
android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>


<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

我期望输出响应200500;但是,实际输出是:

I/System.out: null

最佳答案

EntityUtils.toString(entity) 返回 entity.getContent() - 即使 entity 不是 null/空,它也可能为 null/空。

Check the reply from response.getStatusLine() first.

关于java - 如何使用Azure认知系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com