bingspeech api client
3.1.0
Microsoft Bing语音API客户端用Node.J。
Bing语音API服务的官方文件。
要使用Bing Speech API,您必须有一个订阅密钥。如果您还没有订阅密钥,请在此处获取一个:订阅。
使用NPM安装节点项目中的bingspeech-api-client 。
npm install --save bingspeech-api-client
请参阅下面的示例,介绍如何和语音使用文本(STT)和文本到语音(TTS)。
以下示例代码假设您正在使用Typescript。如果是,请跳过本节,直接进入示例。但是,如果您使用的是节点ES6,并且想使用示例代码读取。
目前,节点不支持import 。如MDN
注意:此功能刚刚在此时才开始在浏览器中
import。它是在许多转下器中实现的,例如Traceur编译器,Babel,Collup或WebPack。
要获得示例代码工作,将第一行更改为:
const { BingSpeechClient , VoiceRecognitionResponse } = require ( 'bingspeech-api-client' ) ; import { BingSpeechClient , VoiceRecognitionResponse } from 'bingspeech-api-client' ;
let audioStream = fs . createReadStream ( myFileName ) ; // create audio stream from any source
// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'your_private_subscription_key' ;
let client = new BingSpeechClient ( subscriptionKey ) ;
client . recognizeStream ( audioStream ) . then ( response => console . log ( response . results [ 0 ] . name ) ) ; import { BingSpeechClient , VoiceVoiceSynthesisResponse } from 'bingspeech-api-client' ;
// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'your_private_subscription_key' ;
let client = new BingSpeechClient ( subscriptionKey ) ;
client . synthesizeStream ( 'I have a dream' ) . then ( audioStream => /* ... */ ) ;