UNPKG

discord-speech-recognition

Version:

Extension for making discord speech recognition bots.

56 lines 1.86 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const wav_1 = __importDefault(require("wav")); class VoiceMessage { /** * Voice message, it is emited `speech` event * @param client * @param data * @param channel * @private */ constructor({ client, data, channel, }) { this.client = client; this.channel = channel; this.author = data.author; this.audioBuffer = data.audioBuffer; this.connection = data.connection; this.duration = data.duration; this.content = data === null || data === void 0 ? void 0 : data.content; this.error = data === null || data === void 0 ? void 0 : data.error; } /** * Saves audio to .wav file * @param filename File directory, for example: `./test.wav` */ saveToFile(filename) { const outputFile = new wav_1.default.FileWriter(filename, VoiceMessage.audioBufferFormat); outputFile.write(this.audioBuffer); outputFile.end(); } /** * Useful if you want to send audio to some API or play it in browser * @returns Wav audio encoded to base64 */ getWavEncodedToBase64Audio() { const writer = new wav_1.default.Writer(VoiceMessage.audioBufferFormat); writer.write(this.audioBuffer); writer.end(); return writer.read(writer.readableLength).toString("base64"); } get member() { return this.guild.members.cache.get(this.author.id); } get guild() { return this.channel.guild; } } exports.default = VoiceMessage; VoiceMessage.audioBufferFormat = { sampleRate: 48000, channels: 1, }; //# sourceMappingURL=VoiceMessage.js.map