ไคลเอนต์ Microsoft Bing Speech API ที่เขียนใน Node.js.
เอกสารอย่างเป็นทางการสำหรับ Bing Speech API Service
ในการทำงานกับ Bing Speech API คุณต้องมีคีย์การสมัครสมาชิก หากคุณไม่มีคีย์การสมัครสมาชิกให้รับที่นี่: การสมัครสมาชิก
ติดตั้ง bingspeech-api-client ในโครงการโหนดของคุณด้วย NPM
npm install --save bingspeech-api-client
ดูตัวอย่างด้านล่างเกี่ยวกับวิธีการต้องการและใช้สำหรับการพูดกับข้อความ (STT) และข้อความเป็นคำพูด (TTS)
รหัสตัวอย่างต่อไปนี้สมมติว่าคุณกำลังใช้ TypeScript หากคุณอยู่ให้ข้ามส่วนนี้และตรงไปที่ตัวอย่าง แต่ถ้าคุณใช้ Node ES6 และต้องการใช้รหัสตัวอย่างที่อ่าน
ในปัจจุบันโหนดไม่รองรับ import ดังที่ได้กล่าวไว้ใน MDN
หมายเหตุ: คุณลักษณะนี้ [
import] เริ่มต้นที่จะนำไปใช้ในเบราว์เซอร์ในเวลานี้เท่านั้น มันถูกนำไปใช้ใน transpilers จำนวนมากเช่นคอมไพเลอร์ Traceur, Babel, Rollup หรือ 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 => /* ... */ ) ;