Created
January 23, 2024 08:37
-
-
Save BettyJJ/14a7f532b4417d257a678066c4b83534 to your computer and use it in GitHub Desktop.
Example of Asure Speech service TTS in React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copy to your component to use it | |
import * as sdk from "microsoft-cognitiveservices-speech-sdk"; | |
function textToSpeech() { | |
const speechKey = process.env.SPEECH_KEY; | |
const speechRegion = process.env.SPEECH_REGION; | |
const speechConfig = sdk.SpeechConfig.fromSubscription(speechKey, speechRegion); | |
const audioConfig = sdk.AudioConfig.fromDefaultSpeakerOutput(); | |
speechConfig.speechSynthesisVoiceName = "en-US-JennyNeural"; | |
const synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig); | |
const text = "Hello, my name is Jenny. What is your name?"; | |
synthesizer.speakTextAsync(text, (result) => { | |
if (result) { | |
synthesizer.close(); | |
return result.audioData; | |
} | |
}, (error) => { | |
console.log(error); | |
synthesizer.close(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment