Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed resultIndex undefined issue while using cognitive service ponyfill, in PR [241](https://github.com/compulim/web-speech-cognitive-services/pull/241) by [@RushikeshGavali](https://github.com/RushikeshGavali)

## [8.1.1] - 2025-01-21

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe.each(testTableForAuthentication)(
[
'result',
{
resultIndex: undefined,
resultIndex: 0,
results: [
{
0: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import textNormalizationSchema from './validation/textNormalizationSchema';
// "Duration": 0
// }

const FINAL_RESULT_OFFSET = 1;

const { ResultReason, SpeechRecognizer } = SpeechSDK;

type CreateSpeechRecognitionPonyfillFromRecognizerInit = {
Expand Down Expand Up @@ -471,7 +473,8 @@ export default function createSpeechRecognitionPonyfillFromRecognizer({
if (!this.continuous || stopping === 'stop') {
// Empty result will turn into "no-speech" later in the code.
finalEvent = new SpeechRecognitionEvent('result', {
results: new SpeechRecognitionResultList(finalizedResults)
results: new SpeechRecognitionResultList(finalizedResults),
resultIndex: finalizedResults.length - FINAL_RESULT_OFFSET
});

// Quirks: 2024-11-19 with Speech SDK 1.14.0
Expand Down Expand Up @@ -521,7 +524,8 @@ export default function createSpeechRecognitionPonyfillFromRecognizer({
this.continuous &&
this.dispatchEvent(
new SpeechRecognitionEvent('result', {
results: new SpeechRecognitionResultList(finalizedResults)
results: new SpeechRecognitionResultList(finalizedResults),
resultIndex: finalizedResults.length - FINAL_RESULT_OFFSET
})
);
}
Expand All @@ -531,7 +535,8 @@ export default function createSpeechRecognitionPonyfillFromRecognizer({
finalEvent = undefined;
} else {
finalEvent = new SpeechRecognitionEvent('result', {
results: new SpeechRecognitionResultList(finalizedResults)
results: new SpeechRecognitionResultList(finalizedResults),
resultIndex: finalizedResults.length - FINAL_RESULT_OFFSET
});
}

Expand All @@ -548,16 +553,18 @@ export default function createSpeechRecognitionPonyfillFromRecognizer({
finalEvent = undefined;
}
} else if (recognizing) {
const results = new SpeechRecognitionResultList([
...finalizedResults,
cognitiveServiceEventResultToWebSpeechRecognitionResult(recognizing.result, {
maxAlternatives: this.maxAlternatives,
textNormalization
})
]);
this.interimResults &&
this.dispatchEvent(
new SpeechRecognitionEvent('result', {
results: new SpeechRecognitionResultList([
...finalizedResults,
cognitiveServiceEventResultToWebSpeechRecognitionResult(recognizing.result, {
maxAlternatives: this.maxAlternatives,
textNormalization
})
])
results,
resultIndex: results.length - FINAL_RESULT_OFFSET
})
);
}
Expand Down