UNPKG

rashi-discord-bot-lib

Version:

🚀 Powerful Discord bot framework with built-in database, event handling, and utilities

53 lines • 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TTSService = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const util_1 = __importDefault(require("util")); const text_to_speech_1 = __importDefault(require("@google-cloud/text-to-speech")); class TTSService { client; constructor() { this.client = new text_to_speech_1.default.TextToSpeechClient(); } async synthesizeToFile(text, options = {}) { const request = { input: { text }, voice: { languageCode: options.languageCode || 'en-US', name: options.voiceName || 'en-US-Wavenet-D', }, audioConfig: { audioEncoding: 'MP3', speakingRate: options.speakingRate || 1.0, pitch: options.pitch || 0, }, }; const [response] = await this.client.synthesizeSpeech(request); const outputPath = options.outputPath || path_1.default.join(process.cwd(), `tts-output-${Date.now()}.mp3`); const writeFile = util_1.default.promisify(fs_1.default.writeFile); await writeFile(outputPath, response.audioContent); return outputPath; } async synthesizeToBuffer(text, options = {}) { const request = { input: { text }, voice: { languageCode: options.languageCode || 'en-US', name: options.voiceName || 'en-US-Wavenet-D', }, audioConfig: { audioEncoding: 'MP3', speakingRate: options.speakingRate || 1.0, pitch: options.pitch || 0, }, }; const [response] = await this.client.synthesizeSpeech(request); return response.audioContent; } } exports.TTSService = TTSService; //# sourceMappingURL=TTSService.js.map