diff --git a/src/commands/tts/setmode.ts b/src/commands/tts/setmode.ts index 6deb396..ad4fb77 100644 --- a/src/commands/tts/setmode.ts +++ b/src/commands/tts/setmode.ts @@ -50,9 +50,11 @@ const cmd: Command = { const modes = TTSManager.get.getModules(); const filtered: string[] = modes - .filter((mode) => - mode.name.toLowerCase().startsWith(focused.value.toLowerCase()) - ) + .filter((mode) => { + return mode.name + ? mode.name.toLowerCase().startsWith(focused.value.toLowerCase()) + : undefined; + }) .map((mode) => mode.name) .slice(0, 25); diff --git a/src/modules/tts-modes/azure.ts b/src/modules/tts-modes/azure.ts index 921e4d4..2272758 100644 --- a/src/modules/tts-modes/azure.ts +++ b/src/modules/tts-modes/azure.ts @@ -1,37 +1,37 @@ -import { TTSModule, TTSResponse } from "../tts"; +import { TTSModule, TTSResponse } from '../tts'; import { VoicesManager, Communicate } from 'edge-tts-universal'; class AzureTTS implements TTSModule { - private voices: Array | undefined = undefined; + private voices: Array | undefined = undefined; - public name: string = "Azure"; - - async getVoices(): Promise | undefined> { - if (!this.voices) { - const voiceMgr = await VoicesManager.create(); - const voiceQuery = await voiceMgr.find({}); + public name: string = 'Azure'; - this.voices = voiceQuery.map((voice) => voice.ShortName); - } + async getVoices(): Promise | undefined> { + if (!this.voices) { + const voiceMgr = await VoicesManager.create(); + const voiceQuery = await voiceMgr.find({}); - return this.voices; - }; + this.voices = voiceQuery.map((voice) => voice.ShortName); + } - async generate(voice: string, text: string): Promise { - const comm = new Communicate(text, { - voice: voice - }); + return this.voices; + } - const buffers: Buffer[] = []; - for await (const chunk of comm.stream()) { - if (chunk.type === 'audio' && chunk.data) { - buffers.push(chunk.data); - } - } + async generate(voice: string, text: string): Promise { + const comm = new Communicate(text, { + voice: voice + }); - return { data: Buffer.concat(buffers) }; - }; + const buffers: Buffer[] = []; + for await (const chunk of comm.stream()) { + if (chunk.type === 'audio' && chunk.data) { + buffers.push(chunk.data); + } + } + + return { data: Buffer.concat(buffers) }; + } } export default new AzureTTS();