@@ -7,11 +7,15 @@ export class PipeWirePlayback extends EventEmitter {
|
||||
}
|
||||
async play(samples) {
|
||||
this.stop();
|
||||
const child = this.process = this.spawnImpl(this.command, ['--playback', '--raw', '--format', 's16', '--rate', String(this.sampleRate), '--channels', '1', '--name', this.nodeName], { stdio: ['pipe', 'ignore', 'pipe'] });
|
||||
child.stderr?.on('data', (chunk) => this.emit('diagnostic', String(chunk).trim()));
|
||||
child.on('error', (error) => this.emit('error', error));
|
||||
child.stdin.end(Buffer.from(samples.buffer, samples.byteOffset, samples.byteLength));
|
||||
await new Promise((resolve, reject) => { child.once('close', resolve); child.once('error', reject); });
|
||||
const child = this.process = this.spawnImpl(this.command, ['--playback', '--raw', '--format', 's16', '--rate', String(this.sampleRate), '--channels', '1', '--properties', `node.name=${this.nodeName}`, '-'], { stdio: ['pipe', 'ignore', 'pipe'] });
|
||||
let diagnostic = '';
|
||||
child.stderr?.on('data', (chunk) => { diagnostic = (diagnostic + String(chunk)).slice(-2048); this.emit('diagnostic', String(chunk).trim()); });
|
||||
await new Promise((resolve, reject) => {
|
||||
child.once('close', (code, signal) => code === 0 || signal === 'SIGTERM' ? resolve() : reject(new Error(`Audio playback exited with code ${code}: ${diagnostic.trim()}`)));
|
||||
child.once('error', reject);
|
||||
child.stdin.on('error', reject);
|
||||
child.stdin.end(Buffer.from(samples.buffer, samples.byteOffset, samples.byteLength));
|
||||
});
|
||||
if (this.process === child) this.process = null;
|
||||
}
|
||||
stop() { if (this.process) { this.process.kill('SIGTERM'); this.process = null; } }
|
||||
|
||||
Reference in New Issue
Block a user