TeaSpeak-Client/native/serverconnection/test/js/audio.ts
2020-03-18 23:32:57 +01:00

65 lines
2.3 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);
stream.set_buffer_latency(0.02);
stream.set_buffer_max_latency(0.2);
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(() => {
handle.audio.sounds.playback_sound({
file: "D:\\TeaSpeak\\web\\shared\\audio\\speech\\connection.refused.wav",
//file: "D:\\Users\\WolverinDEV\\Downloads\\LRMonoPhase4.wav",
volume: 1,
callback: (result, message) => {
console.log("Result %s: %s", handle.audio.sounds.PlaybackResult[result], message);
}
});
}, 500);
/*
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);
*/
});