import { exec } from "child_process"; export interface VolumeSettings { /** * The type of audio stream. * @example "music" */ stream: string; /** * The current volume level of the audio stream. * @example 43 */ volume: number; /** * The maximum volume level of the audio stream. * @example 150 */ max_volume: number; } export interface VolumeOptions { /** * Audio stream to change the volume of */ stream: "alarm|" | "music" | "notification" | "ring" | "system" | "call"; /** * Volume level to set the stream to */ volume: number; } /** * Show information about each audio stream */ export async function volumeInfo(): Promise { return new Promise((resolve, reject) => { const command = `termux-volume`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const settings: VolumeSettings[] = JSON.parse(stdout); return resolve(settings); }); }); } /** * Change volume of audio stream */ export async function volume(options: VolumeOptions): Promise { return new Promise((resolve, reject) => { const command = `termux-volume ${options.stream} ${options.volume}`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } return resolve(); }); }); }