Registry / azure / microsoft-cognitiveservices-speech-sdk

microsoft-cognitiveservices-speech-sdk

JSON →
library1.49.0jsnpmunverified

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.

npm install microsoft-cognitiveservices-speech-sdk
INSTALL
IMPORT
SIG · MICROSOFT-COGNITIV
M
microsoft-cognitiveservices-speech-sdk
azurejavascriptv1.49.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SpeechConfig
import { SpeechConfig } from 'microsoft-cognitiveservices-speech-sdk';
const SpeechConfig = require('microsoft-cognitiveservices-speech-sdk');
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.
SpeechRecognizer
import { SpeechRecognizer } from 'microsoft-cognitiveservices-speech-sdk';
import SpeechRecognizer from 'microsoft-cognitiveservices-speech-sdk';
All core SDK classes are named exports, not default exports. Attempting to use a default import will result in `undefined`.
AudioConfig
import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk';
import { audioConfig } from 'microsoft-cognitiveservices-speech-sdk';
Class names are PascalCase. Using camelCase for named imports will cause a 'module has no exported member' error.

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.

import { SpeechConfig, AudioConfig, SpeechRecognizer, ResultReason } from 'microsoft-cognitiveservices-speech-sdk'; const speechKey: string = process.env.SPEECH_KEY ?? ''; const speechRegion: string = process.env.SPEECH_REGION ?? ''; async function recognizeFromMicrophone(): Promise<void> { if (!speechKey || !speechRegion) { console.error('Please set the SPEECH_KEY and SPEECH_REGION environment variables.'); return; } const speechConfig = SpeechConfig.fromSubscription(speechKey, speechRegion); speechConfig.speechRecognitionLanguage = 'en-US'; const audioConfig = AudioConfig.fromDefaultMicrophoneInput(); const recognizer = new SpeechRecognizer(speechConfig, audioConfig); console.log('Say something into your microphone...'); recognizer.recognizeOnceAsync(result => { switch (result.reason) { case ResultReason.RecognizedSpeech: console.log(`RECOGNIZED: Text=${result.text}`); break; case ResultReason.NoMatch: console.log('NOMATCH: Speech could not be recognized.'); break; case ResultReason.Canceled: const cancellationDetails = result.cancellationDetails; console.log(`CANCELED: Reason=${cancellationDetails?.reason}`); if (cancellationDetails?.errorDetails) { console.log(`CANCELED: ErrorDetails=${cancellationDetails.errorDetails}`); } break; } }); } recognizeFromMicrophone();
Debug
Known issues
breakingSpeaker 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.
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.
affects: >=1.47.0
breakingSpeechRecognizer 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.
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.
affects: >=1.44.0
deprecatedThe `SpeechServiceConnection_EndSilenceTimeoutMs` property has been deprecated. While it may still function, its use is discouraged and it may be removed in future releases.
fix
Migrate to newer properties or methods that control speech segmentation and silence detection. Consult the latest API reference for recommended alternatives.
affects: >=1.46.0
gotchaThe `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.
fix
Consider refactoring `SpeechConfig` initialization to use `SpeechConfig.fromEndpoint()` where applicable, especially for advanced scenarios or custom endpoint configurations.
affects: >=1.44.0
Errors
Common errors & fixes
CANCELED: Reason=ErrorDetails=<Connection was closed by the remote host. ErrorCode: 1000. ErrorType: ConnectionFailure>
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.
fix
Verify that `SPEECH_KEY` and `SPEECH_REGION` are correctly configured and match your Azure resource. Check network connectivity and firewall rules.
TypeError: Cannot read properties of undefined (reading 'recognizeOnceAsync')
This usually happens when `SpeechRecognizer` (or other SDK classes) is not properly initialized, or the `new` keyword is omitted during instantiation.
fix
Ensure that `new SpeechRecognizer(speechConfig, audioConfig)` is used and that `speechConfig` and `audioConfig` are valid instances.
Upgrade
Version history
1.49.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
26
OpenAI (training)
3
Amazon
1
Resources
microsoft-cognitiveservices-speech-sdk — npm install microsoft-cognitiveservices-speech-sdk · libregistry