Skip to content

Commit a5e50c1

Browse files
committed
output device for tts
1 parent 8661615 commit a5e50c1

File tree

10 files changed

+42
-7
lines changed

10 files changed

+42
-7
lines changed

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from config import config
1111
from modules.bot_state import state_manager
12-
from modules.chat import parse_console_logs_and_build_conversation_history
12+
from modules.setup import parse_console_logs_and_build_conversation_history
1313
from modules.commands.gui.openai import gpt3_cmd_handler
1414
from modules.gui.log_window import (
1515
CopyStdoutToSocket,

modules/builder/loaders.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def __load_rcon_command(self):
151151
"model",
152152
"voice",
153153
"speed",
154-
"volume"
154+
"volume",
155+
"output_device"
155156
}
156157
)
157158
}

modules/commands/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def func(logline: LogLine, shared_dict: InitializerConfig) -> Optional[str]:
4242
msg = remove_args(logline.prompt)
4343
result = get_tts(msg, cls.settings)
4444

45-
pygame.mixer.init()
45+
pygame.mixer.init(devicename=cls.settings.get("output_device", None))
4646
sound = pygame.mixer.Sound(io.BytesIO(result.content))
4747
sound.set_volume(cls.settings.get('volume', 1.0))
4848
sound.play()

modules/commands/gui/audio.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from modules.command_controllers import InitializerConfig
2+
from modules.utils.audio import get_devices
3+
from modules.logs import get_logger
4+
5+
gui_logger = get_logger("gui")
6+
7+
8+
def handle_list_devices(command: str, shared_dict: InitializerConfig):
9+
gui_logger.info("Available devices:")
10+
gui_logger.info("#" * 10)
11+
for device in get_devices():
12+
gui_logger.info(f"- {device}")
13+
gui_logger.info("#" * 10)

modules/commands/gui/invoke.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from config import config
2-
from modules.chat import controller
2+
from modules.setup import controller
33
from modules.lobby_manager import lobby_manager
44
from modules.logs import get_logger
55
from modules.typing import LogLine

modules/gui/controller.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
from modules.command_controllers import GuiCommandController
4+
from modules.commands.gui.audio import handle_list_devices
45
from modules.commands.gui.bans import handle_ban, handle_list_bans, handle_unban
56
from modules.commands.gui.config import handle_config
67
from modules.commands.gui.invoke import invoke
@@ -29,3 +30,4 @@
2930
)
3031
command_controller.register_command("quit", lambda *args: sys.exit(0), "Quit the program.")
3132
command_controller.register_command("config", handle_config, config_command_description)
33+
command_controller.register_command("audio-devices", handle_list_devices, "List output audio devices.")

modules/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from config import Config, ValidatableConfig, config
1414
from modules.builder.utils import create_command_from_dict
15-
from modules.chat import controller
15+
from modules.setup import controller
1616
from modules.gui.controller import command_controller as gui_cmd_controller
1717
from modules.logs import get_logger
1818
from modules.set_once_dict import ModificationOfSetKey

modules/chat.py modules/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
controller = CommandController(InitializerConfig())
2323

2424

25-
def setup() -> None:
25+
def init() -> None:
2626
"""
2727
Initializes the program.
2828
"""
@@ -49,7 +49,7 @@ def parse_console_logs_and_build_conversation_history() -> None:
4949
"""
5050
Processes the console logs and builds a conversation history, filters banned usernames.
5151
"""
52-
setup()
52+
init()
5353

5454
# Commands
5555
controller.register_command("!gh", handle_gh_command)

modules/utils/audio.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Tuple
2+
3+
import pygame
4+
import pygame._sdl2.audio as sdl2_audio
5+
6+
7+
def get_devices(capture_devices: bool = False) -> Tuple[str, ...]:
8+
init_by_me = not pygame.mixer.get_init()
9+
if init_by_me:
10+
pygame.mixer.init()
11+
devices = tuple(sdl2_audio.get_audio_device_names(capture_devices))
12+
if init_by_me:
13+
pygame.mixer.quit()
14+
return devices

schemas/commands/openai-tts.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"volume": {
2525
"title": "Volume (0.00 - 1.00)",
2626
"type": "number"
27+
},
28+
"output_device": {
29+
"type": "string",
30+
"title": "Output device",
31+
"description": "Use 'audio-devices' command to get all available devices."
2732
}
2833
},
2934
"required": [

0 commit comments

Comments
 (0)