TeaSpeak-Client/native/serverconnection/test/js/audio.ts
2020-02-13 22:16:34 +01:00

49 lines
1.8 KiB
TypeScript

/// <reference path="../../exports/exports.d.ts" />
console.log("Starting app");
module.paths.push("../../build/linux_x64");
module.paths.push("../../build/win32_x64");
const original_require = require;
require = (module => original_require(__dirname + "/../../../build/win32_x64/" + module + ".node")) as any;
import * as handle from "teaclient_connection";
require = original_require;
console.dir(handle.audio);
handle.audio.initialize(() => {
console.log("Audio initialized");
console.log("Query devices...");
console.log("Devices: %o", handle.audio.available_devices());
console.log("Current playback device: %o", handle.audio.playback.current_device());
const stream = handle.audio.playback.create_stream();
console.log("Own stream: %o", stream);
const recorder = handle.audio.record.create_recorder();
const default_input = handle.audio.available_devices().find(e => e.input_default);
console.log(default_input);
console.log(handle.audio.available_devices().find(e => e.device_id == handle.audio.playback.current_device()));
recorder.set_device(default_input.device_id, () => {
const consumer = recorder.create_consumer();
consumer.callback_data = buffer => {
stream.write_data(buffer.buffer, true);
};
recorder.start(result => {
console.log("Start result: %o", result);
});
});
setInterval(() => {
const elements = handle.audio.available_devices().filter(e => e.input_supported);
const dev = elements[Math.floor(Math.random() * elements.length)];
recorder.set_device(dev.device_id, () => {
console.log("Dev updated: %o", dev);
recorder.start(() => {
console.log("Started");
});
});
}, 1000);
});