wip: add tts debug
This commit is contained in:
parent
b71bedb62a
commit
53dc536d50
4 changed files with 2437 additions and 16 deletions
|
|
@ -18,6 +18,10 @@ dependencies = [
|
|||
"pyinstaller>=6.11.0",
|
||||
"twitchwebsocket>=1.2.1",
|
||||
"loguru>=0.7.2",
|
||||
"ffmpeg>=1.4",
|
||||
"ffmpeg-python>=0.2.0",
|
||||
"simpleaudio>=1.0.4",
|
||||
"coqui-tts>=0.24.3",
|
||||
]
|
||||
|
||||
[tool.uv]
|
||||
|
|
@ -44,7 +48,9 @@ module = [
|
|||
"nltk.tokenize.treebank",
|
||||
"nltk.tokenize.destructive",
|
||||
"TwitchWebsocket",
|
||||
"tokenizer"
|
||||
"tokenizer",
|
||||
"TTS.api",
|
||||
"simpleaudio"
|
||||
]
|
||||
ignore_missing_imports = true
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from kivy.uix.widget import Widget
|
|||
|
||||
from src.markovbot_gui.bot_runner import BotRunner
|
||||
from src.markovbot_gui.config_window import ConfigWindow
|
||||
from src.markovbot_gui.tts_window import TTSWindow
|
||||
|
||||
|
||||
class BotApp(App):
|
||||
|
|
@ -51,6 +52,29 @@ class BotApp(App):
|
|||
|
||||
popup.open()
|
||||
|
||||
def run_tts(self, instance):
|
||||
"""Create a TTS window and open it"""
|
||||
tts_window = TTSWindow(config_path=self.config_path)
|
||||
popup = Popup(
|
||||
title=f"TTS configuration, available at {self.config_path}",
|
||||
content=tts_window,
|
||||
size_hint=(None, None),
|
||||
size=(dp(600), dp(400)),
|
||||
auto_dismiss=False,
|
||||
)
|
||||
|
||||
# Add close button
|
||||
close_button = Button(
|
||||
text="Close",
|
||||
size_hint=(None, None),
|
||||
size=(dp(100), dp(40)),
|
||||
pos_hint={"center_x": 0.5},
|
||||
)
|
||||
close_button.bind(on_release=popup.dismiss)
|
||||
tts_window.add_widget(close_button)
|
||||
|
||||
popup.open()
|
||||
|
||||
def build(self):
|
||||
widget = Widget()
|
||||
|
||||
|
|
@ -60,6 +84,10 @@ class BotApp(App):
|
|||
run_button.bind(on_release=self.run_bot)
|
||||
layout.add_widget(run_button)
|
||||
|
||||
tts_button = Button(text="TTS button")
|
||||
tts_button.bind(on_release=self.run_tts)
|
||||
layout.add_widget(tts_button)
|
||||
|
||||
config_button = Button(text="Open config")
|
||||
config_button.bind(on_release=self.run_config)
|
||||
layout.add_widget(config_button)
|
||||
|
|
|
|||
48
src/markovbot_gui/tts_window.py
Normal file
48
src/markovbot_gui/tts_window.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from pathlib import Path
|
||||
|
||||
from kivy.metrics import dp
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.textinput import TextInput
|
||||
from TTS.api import TTS
|
||||
|
||||
|
||||
class TTSWindow(BoxLayout):
|
||||
def __init__(self, config_path: Path, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.config_path = config_path
|
||||
self.orientation = "vertical"
|
||||
|
||||
self.spacing = dp(10)
|
||||
self.padding = dp(20)
|
||||
|
||||
# create a text input for the text to be converted to audio,
|
||||
# and a button to execute the conversion
|
||||
|
||||
text_layout = BoxLayout(orientation="vertical")
|
||||
self.add_widget(text_layout)
|
||||
|
||||
self.text_input = TextInput(multiline=True)
|
||||
text_layout.add_widget(self.text_input)
|
||||
|
||||
tts_button = Button(text="TTS button")
|
||||
tts_button.bind(on_release=self.run_tts)
|
||||
text_layout.add_widget(tts_button)
|
||||
|
||||
def run_tts(self, instance):
|
||||
device = "cpu"
|
||||
model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
|
||||
tts = TTS(model_name).to(device)
|
||||
tts.download_model_by_name(model_name)
|
||||
|
||||
file = "output.wav"
|
||||
tts.tts_to_file(
|
||||
text=self.text_input.text.strip(),
|
||||
speaker="Rosemary Okafor",
|
||||
language="es",
|
||||
file_path=file,
|
||||
)
|
||||
|
||||
import simpleaudio as sa
|
||||
|
||||
sa.WaveObject.from_wave_file(file).play()
|
||||
Loading…
Add table
Add a link
Reference in a new issue