Skip to content

Commit

Permalink
revertimos y optimisaciones menores.
Browse files Browse the repository at this point in the history
  • Loading branch information
metalalchemist committed Sep 5, 2023
1 parent 9f4c859 commit fa7cf74
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 86 deletions.
69 changes: 1 addition & 68 deletions TTS/Piper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ctypes
import io
import json
import logging
Expand All @@ -9,24 +8,14 @@

import numpy as np
import onnxruntime
from espeak_phonemizer import Phonemizer

_LOGGER = logging.getLogger(__name__)

_BOS = "^"
_EOS = "$"
_PAD = "_"

EE_OK = 0
AUDIO_OUTPUT_SYNCHRONOUS = 0x02
espeakPHONEMES_IPA = 0x02
espeakCHARS_AUTO = 0

CLAUSE_INTONATION_FULL_STOP = 0x00000000
CLAUSE_INTONATION_COMMA = 0x00001000
CLAUSE_INTONATION_QUESTION = 0x00002000
CLAUSE_INTONATION_EXCLAMATION = 0x00003000

CLAUSE_TYPE_SENTENCE = 0x00080000

@dataclass
class PiperConfig:
Expand All @@ -39,62 +28,6 @@ class PiperConfig:
noise_w: float
phoneme_id_map: Mapping[str, Sequence[int]]

class CustomPhonemizer(object):
""" A modified Phonemizer that keeps the punctuation.
Needs a patched libespeak-ng.so from https://github.com/rhasspy/espeak-ng """
def __init__(self, voice):
# Set voice
ret = forked_lib.espeak_SetVoiceByName(voice.encode("utf-8"))
assert ret == EE_OK, ret

def phonemize(self, text):
text_pointer = ctypes.c_char_p(text.encode("utf-8"))

phoneme_flags = espeakPHONEMES_IPA
text_flags = espeakCHARS_AUTO

phonemes = ""
while text_pointer:
terminator = ctypes.c_int(0)
clause_phonemes = forked_lib.espeak_TextToPhonemesWithTerminator(
ctypes.pointer(text_pointer),
text_flags,
phoneme_flags,
ctypes.pointer(terminator),
)
if isinstance(clause_phonemes, bytes):
phonemes += clause_phonemes.decode()

# Check for punctuation.
# The testing order here is critical.
if (terminator.value & CLAUSE_INTONATION_EXCLAMATION) == CLAUSE_INTONATION_EXCLAMATION:
phonemes += "!"
elif (terminator.value & CLAUSE_INTONATION_QUESTION) == CLAUSE_INTONATION_QUESTION:
phonemes += "?"
elif (terminator.value & CLAUSE_INTONATION_COMMA) == CLAUSE_INTONATION_COMMA:
phonemes += ","
elif (terminator.value & CLAUSE_INTONATION_FULL_STOP) == CLAUSE_INTONATION_FULL_STOP:
phonemes += "."

# Check for end of sentence
if (terminator.value & CLAUSE_TYPE_SENTENCE) == CLAUSE_TYPE_SENTENCE:
phonemes += "\n"
else:
phonemes += " "
return phonemes


# Check if we have the patched lib needed to use the CustomPhonemizer
forked_lib_available = False
try:
forked_lib = ctypes.cdll.LoadLibrary("espeak-ng/espeak-ng.dll")
# Will fail if custom function is missing
forked_lib.espeak_TextToPhonemesWithTerminator.restype = ctypes.c_char_p
# Initialize
forked_lib_available = forked_lib.espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, None, 0) > 0
Phonemizer = CustomPhonemizer
except ValueError:
from espeak_phonemizer import Phonemizer

class Piper:
def __init__(
Expand Down
14 changes: 3 additions & 11 deletions TTS/Piper/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ def __init__(self, model_path):
def load_model(self):
if self.voice:
return self.voice
else:
self.voice = Piper(self.model_path)
self.voice = Piper(self.model_path)

def set_rate(self, new_scale):
self.length_scalGe = new_scale

def set_noise_scale(self, new_scale):
self.noise_scale = new_scale

def set_noise_scale_w(self, new_scale):
self.noise_w = new_scale
self.length_scale = new_scale

def set_speaker(self, sid):
self.speaker_id = sid
Expand All @@ -52,5 +45,4 @@ def speak(self, text):
self.noise_scale,
self.noise_w
)
sd.play(audio_norm, sample_rate)
return audio_norm, sample_rate
sd.play(audio_norm, sample_rate)
7 changes: 3 additions & 4 deletions VeTube.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,13 @@ def detenerLectura(self, event):
dlg_mensaje = wx.MessageDialog(self.dialog_mensaje, _("¿Desea salir de esta ventana y detener la lectura de los mensajes?"), _("Atención:"), wx.YES_NO | wx.ICON_ASTERISK)
if dlg_mensaje.ShowModal() == wx.ID_YES:
self.dentro=False
self.usuarios=self.mensajes=[]
if isinstance(self.chat, TikTokLiveClient):
self.chat.stop()
self.gustados=[]
self.megusta=self.unidos=self.seguidores=self.compartidas=0
yt=0
pos=[]
lista=[]
pos=lista=[]
lista=retornarCategorias()
for temporal in lista: pos.append(1)
leer.silence()
Expand Down Expand Up @@ -934,7 +935,6 @@ def recibirYT(self):
if config['sonidos'] and self.chat.status!="past" and config['listasonidos'][0]: playsound(ajustes.rutasonidos[0],False)
self.list_box_1.Append(message['author']['name'] +': ' +message['message'])
else:
self.chat.close()
exit()
self.hilo2.join()
async def on_connect(self,event: ConnectEvent):
Expand Down Expand Up @@ -1272,7 +1272,6 @@ def recibirTwich(self):
if config['sonidos'] and self.chat.status!="past" and config['listasonidos'][0]: playsound(ajustes.rutasonidos[0],False)
self.list_box_1.Append(message['author']['name'] +': ' +message['message'])
else:
self.chat.close()
exit()
self.hilo2.join()
def avanzarCategorias(self):
Expand Down
3 changes: 1 addition & 2 deletions doc/es/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
v2.8
v2.71
Se agrega en el menú contextual de un mensaje una opción llamada lista de URLS. Esto permitirá acceder rápidamente a las urls de los que mandaron el mensaje.
Se agrega nuevo buffer, este se llama mensajes. solo llegan los mensajes de chat, útil para que no se mesclen en la lista general en los en vivos de tiktok.
El conversor de divisas ya está disponible para en vivos en tiktok.
Se solucionaron algunos problemas con la preservación de la puntuación para las voces de Piper, así como también eliminada la limitación de generaciones que ocurría por un error de DLL.
v2.7
se agregan mas datos en las estadísticas del chat si es que el en vivo es de tiktok.
Se agrega la capacidad de actualizar configuraciones, para corregir errores inesperados en caso de que alguna no esté establecida.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
wxPython
git+https://github.com/t1nky/playsound
playsound==1.2.2
TikTokLive
pyperclip
chat_downloader
Expand Down

0 comments on commit fa7cf74

Please sign in to comment.