I’m working on a project using NextJS where I need to implement continuous Speech-to-Text with language detection. While I have successfully set up Speech-to-Text for a single language, I’m struggling to get automatic language detection to work. The documentation seems limited, and I can’t seem to figure out what I’m doing wrong.
Following the Documentation it should be implemented is this way (source)
var autoDetectSourceLanguageConfig = SpeechSDK.AutoDetectSourceLanguageConfig.fromLanguages(["en-US", "de-DE"]); var speechRecognizer = SpeechSDK.SpeechRecognizer.FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig);
This is my part of my component:
useEffect(() => {
const fetchTokenAndSetupRecognizer = async () => {
const tokenObj = await getTokenOrRefresh();
if (tokenObj.authToken && tokenObj.region) {
audioConfig.current = AudioConfig.fromDefaultMicrophoneInput();
const autoDetectLanguages = [
"en-US",
"de-DE"
];
speechConfig.current = SpeechConfig.fromAuthorizationToken(
tokenObj.authToken,
tokenObj.region
);
const autoDetectConfig =
AutoDetectSourceLanguageConfig.fromLanguages(autoDetectLanguages);
audioConfig.current = AudioConfig.fromDefaultMicrophoneInput();
recognizer.current = SpeechRecognizer.FromConfig(
speechConfig.current,
autoDetectConfig,
audioConfig.current
);
recognizer.current.recognized = (s, e) =>
processRecognizedTranscript(e);
recognizer.current.canceled = (s, e) => handleCanceled(e);
}
setIsDisabled(!recognizer.current);
};
fetchTokenAndSetupRecognizer();
return () => {
recognizer.current?.close();
};
}, []);
I searched through here, the documentation, and the repository, but there are limited examples and information for React/JavaScript
2
Answers
I tried your code and encountered issues with implementing automatic language detection in Azure Speech-to-Text using the Azure Speech SDK.
To enable language identification, you should use code like this.
Below code is recognizing speech from an audio file using the Azure Speech SDK and the code is taken from MSDOC and git.
Output:
@jojak did you resolved the issue? i am also tried to capture the audio from microphone. it wont works well