开发 AIoT 智能眼镜SDK 开发指南 语音识别服务 语音对接ASR服务

语音对接ASR服务 最后更新时间: 2026年05月27日

服务接口: https://aiot.amap.com/rest/aiot/asr

接口文档:开平透传阿里云接口,阿里云接口文档

语音转文字

示例代码:

/**
 * 发布语音转文字 语音对接ASR服务
 *
 * @param filePath。语音文件名称
 * @param format :音频格式,包括PCM、WAV、OPUS、SPEEX、AMR、MP3、AAC。
 * @param sampleRate:音频采样率。取值:16000 Hz、8000 Hz。默认值:16000 Hz。
 * @param callback :接口类 ,用于数据回掉。
 */
public static void sendVoiceNetNew(String filePath, String format, int sampleRate, VoiceCallback callback)
{

    // Constant.ASR_URL :https://aiot.amap.com/rest/aiot/asr(接口地址)
    // Constant.VI_KEY :开放平台申请的Key
    String requestUrl = Constant.ASR_URL;
    requestUrl = requestUrl + "?key=" + Constant.VI_KEY;
    requestUrl = requestUrl + "&format=" + format;
    requestUrl = requestUrl + "&sample_rate=" + sampleRate;
    requestUrl = requestUrl + "&enable_punctuation_prediction=" + true;
    requestUrl = requestUrl + "&enable_inverse_text_normalization=" + true;
    requestUrl = requestUrl + "&enable_voice_detection=" + true;
    requestUrl = requestUrl + "&disfluency=" + true;

    Log.e(VoiceActivity.TAG, "Request " + requestUrl);

    RequestBody body;
    File file = new File(filePath);
    if (!file.isFile())
    {
        Log.e(VoiceActivity.TAG, "The filePath is not a file: " + filePath);
        return;
    }
    else
    {
        body = RequestBody.create(MediaType.parse("application/octet-stream"), file);
    }

    OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
    Request request = new Request.Builder().url(requestUrl).post(body).build();
    okHttpClient.newCall(request).enqueue(new Callback() {
        @Override
            public void
            onFailure(@NonNull Call call, @NonNull IOException e)
        {

            callback.onError(e.toString());
        }

        @Override
            public void
            onResponse(@NonNull Call call, @NonNull Response response) throws IOException
        {
            String str = response.body().string();

            callback.onsuccess(str);
        }
    });
}

返回顶部 示例中心 常见问题 智能客服 公众号
二维码