Synthesis black list

This commit is contained in:
norohind 2022-03-16 16:35:23 +03:00
parent 5599ca7a35
commit d89c98fea5
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
2 changed files with 32 additions and 3 deletions

13
DB.py
View File

@ -1,3 +1,5 @@
from datetime import datetime
import peewee
database = peewee.SqliteDatabase('voice_cache.sqlite')
@ -18,5 +20,16 @@ class Speaker(BaseModel):
speaker = peewee.CharField()
class SynthesisErrors(peewee.Model):
speaker = peewee.CharField()
text = peewee.TextField()
timestamp = peewee.DateTimeField(default=datetime.now)
class Meta:
database = database
primary_key = peewee.CompositeKey('speaker', 'text')
Prefix.create_table()
Speaker.create_table()
SynthesisErrors.create_table()

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import subprocess
from discord.ext import commands
from discord.ext.commands import Context
import discord
@ -62,10 +64,24 @@ class TTSCommands(commands.Cog, Observ.Observer):
speaker: Speakers = await self._get_speaker(message.guild.id)
wav_file_like_object = self.tts.synthesize_text(message.content, speaker=speaker)
sound_source = FFmpegPCMAudio(wav_file_like_object, pipe=True)
# check if message will fail on synthesis
if DB.SynthesisErrors.select()\
.where(DB.SynthesisErrors.speaker == speaker.value)\
.where(DB.SynthesisErrors.text == message.content)\
.count() == 1:
# Then we will not try to synthesis it
await message.channel.send(f"I will not synthesis this message due to TTS engine limitations")
return
voice_client.play(sound_source)
try:
wav_file_like_object = self.tts.synthesize_text(message.content, speaker=speaker)
sound_source = FFmpegPCMAudio(wav_file_like_object, pipe=True, stderr=subprocess.PIPE)
voice_client.play(sound_source)
except Exception as synth_exception:
logger.warning(f'Exception on synthesize {message.content!r}: {synth_exception}', exc_info=synth_exception)
await message.channel.send(f'Internal error')
DB.SynthesisErrors.create(speaker=speaker.value, text=message.content)
@commands.command('getAllSpeakers')
async def get_speakers(self, ctx: Context):