@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
56 lines (50 loc) • 1.26 kB
text/typescript
import { exec } from "child_process";
/**
* Represents the TTS (Text-to-Speech) engine information.
*/
export interface TTSEngine {
/**
* The name of the TTS engine.
* @example "com.google.android.tts"
*/
name: string;
/**
* The label of the TTS engine.
* @example "Speech Recognition and Synthesis from Google"
*/
label: string;
/**
* Indicates if this is the default TTS engine.
* @example true
*/
default: boolean;
}
/**
* Represents the TTS engines information.
*/
export interface TTSEnginesInfo {
/**
* List of TTS engines.
*/
engines: TTSEngine[];
}
/**
* Get information about the available text-to-speech (TTS) engines.
* The name of an engine may be given to the termux-tts-speak
*/
export async function ttsEngines(): Promise<TTSEnginesInfo> {
return new Promise<TTSEnginesInfo>((resolve, reject) => {
const command = `termux-tts-engines`;
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const enginesInfo: TTSEnginesInfo = JSON.parse(output);
return resolve(enginesInfo);
});
});
}