Skip to content

Commit

Permalink
Try to fix Unable to use Speech Recognition #1139
Browse files Browse the repository at this point in the history
Issue: #1139
  • Loading branch information
xdan committed May 19, 2024
1 parent dfb7f0d commit 065bf2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/plugins/speech-recognize/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { ISpeechRecognizeConstructor } from './interface';
import { SpeechRecognition } from './helpers/api';
import { RecognizeManager } from './helpers/recognize-manager';
import speechRecognizeIcon from './speech-recognize.svg';
import { attr, isString } from 'jodit/core/helpers';

declare module 'jodit/config' {
interface Config {
Expand Down Expand Up @@ -131,7 +132,10 @@ Config.prototype.controls.speechRecognize = {
const nativeApi = new ApiConstructor();
api = new RecognizeManager(jodit.async, nativeApi);

api.lang = lang;
api.lang = isString(lang)
? lang
: attr(jodit.od.documentElement, 'lang') ?? undefined;

api.continuous = continuous;
api.interimResults = interimResults;
api.sound = sound;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/speech-recognize/helpers/recognize-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ export class RecognizeManager

for (let i = 0; i < e.results.length; i++) {
const resultItem = e.results.item(i);
const { transcript } = resultItem.item(0);
this.__interimResults += transcript;
if (resultItem.length) {
const { transcript } = resultItem.item(0);
this.__interimResults += transcript;
}
}

if (this.__interimResults) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/speech-recognize/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ISpeechRecognizeResult {
item(index: number): {
isFinal?: boolean;
item(subIndex: number): { transcript: string };
length: number;
};
length: number;
};
Expand Down

0 comments on commit 065bf2d

Please sign in to comment.