Azure Speech Service provides advanced speech-to-text, text-to-speech, and speech translation capabilities. It enables developers to add natural language interaction to applications, devices, and services.
Below is a minimal example that captures microphone audio and displays the recognized text.
<script src="https://aka.ms/csspeech/jsbrowserpackageraw"></script>
<script>
const subscriptionKey = "YOUR_SUBSCRIPTION_KEY";
const serviceRegion = "YOUR_SERVICE_REGION";
const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
speechConfig.speechRecognitionLanguage = "en-US";
const audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
const recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
recognizer.recognized = (s, e) => {
if (e.result.text) {
document.getElementById("result").textContent = e.result.text;
}
};
recognizer.canceled = (s, e) => {
console.error(e);
recognizer.stopContinuousRecognitionAsync();
};
const startBtn = document.getElementById("start");
startBtn.onclick = () => {
startBtn.disabled = true;
recognizer.startContinuousRecognitionAsync();
};
</script>