@freddydrodev/artyom
Version:
Artyom is a Robust Wrapper of the Google Chrome SpeechSynthesis and SpeechRecognition that allows you to create a virtual assistent
174 lines (164 loc) • 5.33 kB
text/typescript
interface ArtyomCommand {
indexes: string[];
action: (index: number, wildcard?: any, full?: string) => void;
description?: string;
smart?: boolean;
}
interface SayCallbacksObject {
lang?: string;
onStart?: () => void;
onEnd?: () => void;
}
interface ArtyomProperties {
lang: string;
recognizing: boolean;
continuous: boolean;
speed: number;
volume: number;
listen: boolean;
mode: "command" | "dictation" | "normal";
debug: boolean;
helpers: {
fatalityPromiseCallback?: () => void;
redirectRecognizedTextOutput?: (text: string, isFinal: boolean) => void;
remoteProcessorHandler?: (text: string) => void;
lastSay?: { text: string; date: Date };
};
executionKeyword?: string;
obeyKeyword?: string;
speaking: boolean;
obeying: boolean;
soundex: boolean;
name?: string;
voice?: SpeechSynthesisVoice | null;
}
interface PromptOptions {
question: string;
options: string[];
beforePrompt?: () => void;
onStartPrompt?: () => void;
onEndPrompt?: () => void;
onMatch?: (index: number, wildcard: string) => () => void;
smart?: boolean;
}
interface MatchedCommand {
index: number;
instruction: ArtyomCommand;
wildcard?: {
item: string;
full: string;
};
}
interface ArtyomGarbageCollection {
[key: string]: any;
}
interface ArtyomWebkitSpeechRecognition {
continuous: boolean;
interimResults: boolean;
lang: string;
start: () => void;
stop: () => void;
abort: () => void;
onresult: (event: SpeechRecognitionEvent) => void;
onerror: (event: SpeechRecognitionErrorEvent) => void;
onend: () => void;
}
declare global {
interface Window {
webkitSpeechRecognition: new () => ArtyomWebkitSpeechRecognition;
}
}
/**
* Artyom.js is a voice control, speech recognition and speech synthesis JavaScript library.
*
* @requires {webkitSpeechRecognition && speechSynthesis}
* @license MIT
* @version 1.0.6
* @copyright 2017 Our Code World (www.ourcodeworld.com) All Rights Reserved.
* @author Carlos Delgado (https://github.com/sdkcarlos) and Sema García (https://github.com/semagarcia)
* @see https://sdkcarlos.github.io/sites/artyom.html
* @see http://docs.ourcodeworld.com/projects/artyom-js
*/
declare class Artyom {
private readonly ArtyomVoicesIdentifiers;
private artyomWebkitSpeechRecognition;
private ArtyomVoice;
private ArtyomCommands;
private ArtyomGarbageCollection;
private ArtyomFlags;
private ArtyomProperties;
private readonly ArtyomGlobalEvents;
private readonly Device;
constructor();
private initializeDevice;
private initializeSpeechRecognition;
private setupSpeechRecognitionEvents;
private handleSpeechResult;
addCommands(param: ArtyomCommand | ArtyomCommand[]): boolean;
clearGarbageCollection(): ArtyomGarbageCollection[];
debug(message: string, type?: "error" | "warn" | "info"): void;
detectErrors(): {
code: string;
message: string;
} | false;
emptyCommands(): ArtyomCommand[];
fatality(): Promise<void>;
getAvailableCommands(): ArtyomCommand[];
getVoices(): SpeechSynthesisVoice[];
speechSupported(): boolean;
recognizingSupported(): boolean;
shutUp(): void;
getProperties(): ArtyomProperties;
getLanguage(): string;
getVersion(): string;
on(indexes: string[], smart?: boolean): {
then: (action: () => void) => void;
};
triggerEvent(name: string, param?: any): CustomEvent;
repeatLastSay(returnObject?: boolean): {
text: string;
date: Date;
} | void;
when(event: string, action: (detail: any) => void): void;
remoteProcessorService(action: (text: string) => void): boolean;
voiceAvailable(languageCode: string): boolean;
isObeying(): boolean;
obey(): boolean;
dontObey(): boolean;
isSpeaking(): boolean;
isRecognizing(): boolean;
getNativeApi(): ArtyomWebkitSpeechRecognition;
getGarbageCollection(): ArtyomGarbageCollection[];
getVoice(languageCode: string): SpeechSynthesisVoice | undefined;
newDictation(settings: {
onResult?: (interim: string, final: string) => void;
onStart?: () => void;
onEnd?: () => void;
onError?: (event: any) => void;
continuous?: boolean;
}): {
start: () => void;
stop: () => void;
onError: null | ((event: any) => void);
};
newPrompt(config: PromptOptions): void;
sayRandom(data: string[]): {
text: string;
index: number;
} | null;
setDebug(status: boolean): boolean;
simulateInstruction(sentence: string): boolean;
soundex(s: string): string;
splitStringByChunks(input?: string, chunk_length?: number): string[];
redirectRecognizedTextOutput(action: (text: string, isFinal: boolean) => void): boolean;
restart(): Promise<void>;
private talk;
say(message: string, callbacks?: SayCallbacksObject): void;
execute(command: string | ArtyomCommand): MatchedCommand | undefined;
private findCommand;
initialize(config: Partial<ArtyomProperties>): void;
setVoice(voice: SpeechSynthesisVoice | null): void;
flatMap<T>(array: T[], callback: (item: T) => T[]): T[];
addEventListener(type: string, listener: EventListenerOrEventListenerObject): void;
}
export { Artyom as default };