Skip to content
Merged
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
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@ const modelKey = "<key for the speech model>";

// Live transcription from microphone
let transcriber = speech.createTranscriber(
{ modelName, modelPath, modelKey, signal, wavPath: undefined },
{ modelName, modelPath, modelKey },
(err, res) => console.log(err, res)
);
transcriber.start();
// later when done...
// you can stop/start later
transcriber.stop();

// Transcription from *.wav file
transcriber = speech.createTranscriber(
{ modelName, modelPath, modelKey, signal, wavPath: "path-to-wav-file" },
(err, res) => console.log(err, res)
);
transcriber.start();
// later when done...
transcriber.stop();
transcriber.dispose();
```

## Usage: Keyword Recognition
Expand Down
40 changes: 20 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export const speechapi = require('bindings')('speechapi.node') as SpeechLib;
interface SpeechLib {

// Transcription
createTranscriber: (modelPath: string, modelName: string, modelKey: string, wavPath: string | undefined, logsPath: string | undefined, callback: (error: Error | undefined, result: ITranscriptionResult) => void) => number,
createTranscriber: (modelPath: string, modelName: string, modelKey: string, logsPath: string | undefined, phrases: string[], callback: (error: Error | undefined, result: ITranscriptionResult) => void) => number,
startTranscriber: (id: number) => void,
stopTranscriber: (id: number) => void,
disposeTranscriber: (id: number) => void,

// Keyword Recognition
recognize: (modelPath: string, callback: (error: Error | undefined, result: IKeywordRecognitionResult) => void) => number,
Expand All @@ -29,7 +30,8 @@ export enum TranscriptionStatusCode {
SPEECH_START_DETECTED = 7,
SPEECH_END_DETECTED = 8,
STOPPED = 9,
ERROR = 10
DISPOSED = 10,
ERROR = 11
}

export interface ITranscriptionResult {
Expand All @@ -47,37 +49,35 @@ export interface ITranscriptionOptions {
readonly modelKey: string;

/**
* Path to the wav file to transcribe. If not specified, the audio
* will be streamed from the microphone.
* The path to a file to store verbose logs from the Azure Speech SDK to.
*
* @see https://learn.microsoft.com/en-us/azure/ai-services/speech-service/how-to-use-logging
*/
readonly wavPath?: string;
readonly logsPath?: string;

/**
* Path to a file to store verbose logs from the Azure Speech SDK to.
* A phrase list is a list of words or phrases provided ahead of time to help
* improve their recognition. Adding a phrase to a phrase list increases its
* importance, thus making it more likely to be recognized.
*
* @see https://learn.microsoft.com/en-us/azure/ai-services/speech-service/improve-accuracy-phrase-list
*/
readonly logsPath?: string;

readonly signal: AbortSignal;
readonly phrases?: string[];
}

export interface ITranscriber {
start(): void;
stop(): void;
dispose(): void;
}

export function createTranscriber({ modelPath, modelName, modelKey, signal, wavPath, logsPath }: ITranscriptionOptions, callback: ITranscriptionCallback): ITranscriber {
const id = speechapi.createTranscriber(modelPath, modelName, modelKey, wavPath ?? undefined, logsPath ?? undefined, callback);

const onAbort = () => {
speechapi.stopTranscriber(id);
signal.removeEventListener('abort', onAbort);
};

signal.addEventListener('abort', onAbort);
export function createTranscriber({ modelPath, modelName, modelKey, phrases, logsPath }: ITranscriptionOptions, callback: ITranscriptionCallback): ITranscriber {
const id = speechapi.createTranscriber(modelPath, modelName, modelKey, logsPath ?? undefined, phrases ?? [], callback);

return {
start: () => speechapi.startTranscriber(id),
stop: () => speechapi.stopTranscriber(id)
stop: () => speechapi.stopTranscriber(id),
dispose: () => speechapi.disposeTranscriber(id)
};
}

Expand All @@ -88,7 +88,7 @@ export function createTranscriber({ modelPath, modelName, modelKey, signal, wavP
export enum KeywordRecognitionStatusCode {
RECOGNIZED = 3,
STOPPED = 9,
ERROR = 10
ERROR = 11
}

export interface IKeywordRecognitionResult {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/node-speech",
"version": "1.2.3",
"version": "1.3.0",
"description": "Native bindings for Micrsooft Speech SDK",
"repository": {
"type": "git",
Expand Down
Loading