scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
87 lines (77 loc) • 1.66 kB
text/typescript
import {AbsSpeech} from 'scriptable-abstract';
interface SpeechState {
lastSpokenText: string | null;
lastLanguage: string | null;
lastRate: number | null;
lastPitch: number | null;
}
/**
* Mock implementation of Scriptable's Speech global variable
* Provides functionality for text-to-speech conversion
*
* @implements Speech
*/
export class MockSpeech extends AbsSpeech<SpeechState> {
static get instance(): MockSpeech {
return super.instance as MockSpeech;
}
constructor() {
super({
lastSpokenText: null,
lastLanguage: null,
lastRate: null,
lastPitch: null,
});
}
/**
* @inheritdoc
*/
async speak(text: string, language?: string, rate?: number, pitch?: number): Promise<void> {
this.setState({
lastSpokenText: text,
lastLanguage: language || null,
lastRate: rate || null,
lastPitch: pitch || null,
});
}
/**
* @additional
* Get the last spoken text
*/
getLastSpokenText(): string | null {
return this.state.lastSpokenText;
}
/**
* @additional
* Get the last used language
*/
getLastLanguage(): string | null {
return this.state.lastLanguage;
}
/**
* @additional
* Get the last used rate
*/
getLastRate(): number | null {
return this.state.lastRate;
}
/**
* @additional
* Get the last used pitch
*/
getLastPitch(): number | null {
return this.state.lastPitch;
}
/**
* @additional
* Clear speech history
*/
clear(): void {
this.setState({
lastSpokenText: null,
lastLanguage: null,
lastRate: null,
lastPitch: null,
});
}
}