android语音识别服务,使用语音服务 API 的语音识别 - Xamarin | Microsoft Docs

使用 Azure Speech Service 进行语音识别Speech recognition using Azure Speech Service

01/14/2020

本文内容

Azure Speech Service 是一种基于云的 API,它提供以下功能:Azure Speech Service is a cloud-based API that offers the following functionality:

语音到文本 转录音频文件或流到文本。Speech-to-text transcribes audio files or streams to text.

文本到语音 转换将输入文本转换为用户喜欢的合成语音。Text-to-speech converts input text into human-like synthesized speech.

语音翻译 为语音到文本和语音到语音转换启用了实时、多语言翻译。Speech translation enables real-time, multi-language translation for both speech-to-text and speech-to-speech.

语音助手 可为应用程序创建类似于用户的对话接口。Voice assistants can create human-like conversation interfaces for applications.

本文介绍如何 :::no-loc(Xamarin.Forms)::: 使用 Azure 语音服务在示例应用程序中实现语音到文本。This article explains how speech-to-text is implemented in the sample :::no-loc(Xamarin.Forms)::: application using the Azure Speech Service. 以下屏幕截图显示了 iOS 和 Android 上的示例应用程序:The following screenshots show the sample application on iOS and Android:

android语音识别服务,使用语音服务 API 的语音识别 - Xamarin | Microsoft Docs_第1张图片android语音识别服务,使用语音服务 API 的语音识别 - Xamarin | Microsoft Docs_第2张图片

创建 Azure 语音服务资源Create an Azure Speech Service resource

Azure Speech Service 是 Azure 认知服务的一部分,可为图像识别、语音识别和翻译等任务和必应搜索提供基于云的 Api。Azure Speech Service is part of Azure Cognitive Services, which provides cloud-based APIs for tasks such as image recognition, speech recognition and translation, and Bing search.

示例项目需要在 Azure 门户中创建 Azure 认知服务资源。The sample project requires an Azure Cognitive Services resource to be created in your Azure portal. 可以为单个服务(如语音服务)或多服务资源创建认知服务资源。A Cognitive Services resource can be created for a single service, such as Speech Service, or as a multi-service resource. 创建语音服务资源的步骤如下所示:The steps to create a Speech Service resource are as follows:

创建多服务或单一服务资源。Create a multi-service or single-service resource.

获取资源的 API 密钥和区域信息。Obtain the API key and region information for your resource.

更新示例 Constants.cs 文件。Update the sample Constants.cs file.

有关创建资源的循序渐进指南,请参阅 创建认知服务资源。For a step-by-step guide to creating a resource, see Create a Cognitive Services resource.

备注

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户。If you don't have an Azure subscription, create a free account before you begin. 拥有帐户后,可以在免费层创建单个服务资源来试用服务。Once you have an account, a single-service resource can be created at the free tier to try out the service.

通过语音服务配置应用Configure your app with the Speech Service

创建认知服务资源后,可使用 Azure 资源中的区域和 API 密钥更新 Constants.cs 文件:After creating a Cognitive Services resource, the Constants.cs file can be updated with the region and API key from your Azure resource:

public static class Constants

{

public static string CognitiveServicesApiKey = "YOUR_KEY_GOES_HERE";

public static string CognitiveServicesRegion = "westus";

}

安装 NuGet 语音服务包Install NuGet Speech Service package

示例应用程序使用 cognitiveservices account NuGet 包来连接到 Azure 语音服务。The sample application uses the Microsoft.CognitiveServices.Speech NuGet package to connect to the Azure Speech Service. 在共享项目和每个平台项目中安装此 NuGet 包。Install this NuGet package in the shared project and each platform project.

创建 IMicrophoneService 接口Create an IMicrophoneService interface

每个平台都需要有权访问麦克风。Each platform requires permission to access to the microphone. 示例项目 IMicrophoneService 在共享项目中提供了一个接口,并使用 :::no-loc(Xamarin.Forms)::: DependencyService 来获取接口的平台实现。The sample project provides an IMicrophoneService interface in the shared project, and uses the :::no-loc(Xamarin.Forms)::: DependencyService to obtain platform implementations of the interface.

public interface IMicrophoneService

{

Task GetPermissionAsync();

void OnRequestPermissionResult(bool isGranted);

}

创建页面布局Create the page layout

示例项目定义了 MainPage 文件中的基本页面布局。The sample projec

你可能感兴趣的:(android语音识别服务)