UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

75 lines (65 loc) 1.62 kB
import { exec } from "child_process"; /** * Represents the audio configuration settings. */ export interface AudioConfig { /** * The output sample rate. * @example "48000" */ PROPERTY_OUTPUT_SAMPLE_RATE: string; /** * The number of output frames per buffer. * @example "192" */ PROPERTY_OUTPUT_FRAMES_PER_BUFFER: string; /** * The sample rate for AudioTrack. * @example 48000 */ AUDIOTRACK_SAMPLE_RATE: number; /** * The buffer size in frames for AudioTrack. * @example 3844 */ AUDIOTRACK_BUFFER_SIZE_IN_FRAMES: number; /** * The low latency sample rate for AudioTrack. * @example 48000 */ AUDIOTRACK_SAMPLE_RATE_LOW_LATENCY: number; /** * The low latency buffer size in frames for AudioTrack. * @example 192 */ AUDIOTRACK_BUFFER_SIZE_IN_FRAMES_LOW_LATENCY: number; /** * Indicates if Bluetooth A2DP is on. * @example false */ BLUETOOTH_A2DP_IS_ON: boolean; /** * Indicates if a wired headset is connected. * @example false */ WIREDHEADSET_IS_CONNECTED: boolean; } /** * Get information about audio capabilities */ export async function audioInfo(): Promise<AudioConfig> { return new Promise<AudioConfig>((resolve, reject) => { const command = `termux-audio-info`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const settings: AudioConfig = JSON.parse(stdout); return resolve(settings); }); }); }