{"id":11322,"library":"microsoft-cognitiveservices-speech-sdk","title":"Microsoft Azure Cognitive Services Speech SDK for JavaScript","description":"The Microsoft Cognitive Services Speech SDK for JavaScript provides robust APIs for integrating speech-to-text, text-to-speech, and speech translation capabilities into JavaScript applications. It supports both browser and Node.js environments, making it versatile for various use cases. The current stable version is 1.49.0, with a release cadence that appears to be monthly or bi-monthly, indicating active development and continuous feature enhancements. Key differentiators include official support for Azure Speech Services, comprehensive feature set for speech AI, and first-class TypeScript type definitions, enabling a more robust development experience compared to generic WebSocket or REST API integrations.","status":"active","version":"1.49.0","language":"javascript","source_language":"en","source_url":"https://github.com/Microsoft/cognitive-services-speech-sdk-js","tags":["javascript","microsoft","cognitiveservices","speech","sdk","typescript","ts","js"],"install":[{"cmd":"npm install microsoft-cognitiveservices-speech-sdk","lang":"bash","label":"npm"},{"cmd":"yarn add microsoft-cognitiveservices-speech-sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add microsoft-cognitiveservices-speech-sdk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM imports are standard. CommonJS `require` can be used in older Node.js projects but is not recommended for new development due to potential bundling or tree-shaking issues.","wrong":"const SpeechConfig = require('microsoft-cognitiveservices-speech-sdk');","symbol":"SpeechConfig","correct":"import { SpeechConfig } from 'microsoft-cognitiveservices-speech-sdk';"},{"note":"All core SDK classes are named exports, not default exports. Attempting to use a default import will result in `undefined`.","wrong":"import SpeechRecognizer from 'microsoft-cognitiveservices-speech-sdk';","symbol":"SpeechRecognizer","correct":"import { SpeechRecognizer } from 'microsoft-cognitiveservices-speech-sdk';"},{"note":"Class names are PascalCase. Using camelCase for named imports will cause a 'module has no exported member' error.","wrong":"import { audioConfig } from 'microsoft-cognitiveservices-speech-sdk';","symbol":"AudioConfig","correct":"import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk';"}],"quickstart":{"code":"import { SpeechConfig, AudioConfig, SpeechRecognizer, ResultReason } from 'microsoft-cognitiveservices-speech-sdk';\n\nconst speechKey: string = process.env.SPEECH_KEY ?? '';\nconst speechRegion: string = process.env.SPEECH_REGION ?? '';\n\nasync function recognizeFromMicrophone(): Promise<void> {\n    if (!speechKey || !speechRegion) {\n        console.error('Please set the SPEECH_KEY and SPEECH_REGION environment variables.');\n        return;\n    }\n\n    const speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion);\n    speechConfig.speechRecognitionLanguage = 'en-US';\n\n    const audioConfig = AudioConfig.fromDefaultMicrophoneInput();\n    const recognizer = new SpeechRecognizer(speechConfig, audioConfig);\n\n    console.log('Say something into your microphone...');\n\n    recognizer.recognizeOnceAsync(result => {\n        switch (result.reason) {\n            case ResultReason.RecognizedSpeech:\n                console.log(`RECOGNIZED: Text=${result.text}`);\n                break;\n            case ResultReason.NoMatch:\n                console.log('NOMATCH: Speech could not be recognized.');\n                break;\n            case ResultReason.Canceled:\n                const cancellationDetails = result.cancellationDetails;\n                console.log(`CANCELED: Reason=${cancellationDetails?.reason}`);\n                if (cancellationDetails?.errorDetails) {\n                    console.log(`CANCELED: ErrorDetails=${cancellationDetails.errorDetails}`);\n                }\n                break;\n        }\n    });\n}\n\nrecognizeFromMicrophone();","lang":"typescript","description":"Demonstrates basic speech-to-text recognition from microphone input, showing how to configure the SDK, listen for speech, and process the recognized text or cancellation events."},"warnings":[{"fix":"If migrating is not an option, pin the SDK version to `1.46.x` or earlier. For new development, avoid using these deprecated features entirely.","message":"Speaker recognition and intent recognition support were removed from the SDK. Applications relying on these features must use older versions of the SDK or migrate to alternative services/implementations.","severity":"breaking","affected_versions":">=1.47.0"},{"fix":"Review and update application logic that specifically handles `NoMatch` results. The SDK's behavior around partial and final results should be re-evaluated to accommodate this change.","message":"SpeechRecognizer and TranslationRecognizer were updated to use V2 endpoints by default. This change means that `NoMatch` results may no longer be received as they were in previous versions, significantly altering recognition behavior.","severity":"breaking","affected_versions":">=1.44.0"},{"fix":"Migrate to newer properties or methods that control speech segmentation and silence detection. Consult the latest API reference for recommended alternatives.","message":"The `SpeechServiceConnection_EndSilenceTimeoutMs` property has been deprecated. While it may still function, its use is discouraged and it may be removed in future releases.","severity":"deprecated","affected_versions":">=1.46.0"},{"fix":"Consider refactoring `SpeechConfig` initialization to use `SpeechConfig.fromEndpoint()` where applicable, especially for advanced scenarios or custom endpoint configurations.","message":"The `FromEndpoint` API is now the recommended method for constructing a `SpeechConfig` for most scenarios, especially when working with `SpeechRecognizer`. While `FromSubscription` still works, `FromEndpoint` offers more flexibility and control.","severity":"gotcha","affected_versions":">=1.44.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that `SPEECH_KEY` and `SPEECH_REGION` are correctly configured and match your Azure resource. Check network connectivity and firewall rules.","cause":"This error typically indicates an issue with the authentication key or region, or network connectivity problems preventing the WebSocket connection to the Azure Speech Service.","error":"CANCELED: Reason=ErrorDetails=<Connection was closed by the remote host. ErrorCode: 1000. ErrorType: ConnectionFailure>"},{"fix":"Ensure that `new SpeechRecognizer(speechConfig, audioConfig)` is used and that `speechConfig` and `audioConfig` are valid instances.","cause":"This usually happens when `SpeechRecognizer` (or other SDK classes) is not properly initialized, or the `new` keyword is omitted during instantiation.","error":"TypeError: Cannot read properties of undefined (reading 'recognizeOnceAsync')"}],"ecosystem":"npm"}