mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-28 02:14:44 +01:00
Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com> Co-authored-by: Nicholas Tindle <nick@ntindle.com> Co-authored-by: Luke K (pr-0f3t) <2609441+lc0rp@users.noreply.github.com>
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
"""Base class for all voice classes."""
|
|
import abc
|
|
import re
|
|
from threading import Lock
|
|
|
|
from autogpt.singleton import AbstractSingleton
|
|
|
|
|
|
class VoiceBase(AbstractSingleton):
|
|
"""
|
|
Base class for all voice classes.
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""
|
|
Initialize the voice class.
|
|
"""
|
|
self._url = None
|
|
self._headers = None
|
|
self._api_key = None
|
|
self._voices = []
|
|
self._mutex = Lock()
|
|
self._setup()
|
|
|
|
def say(self, text: str, voice_index: int = 0) -> bool:
|
|
"""
|
|
Say the given text.
|
|
|
|
Args:
|
|
text (str): The text to say.
|
|
voice_index (int): The index of the voice to use.
|
|
"""
|
|
text = re.sub(
|
|
r"\b(?:https?://[-\w_.]+/?\w[-\w_.]*\.(?:[-\w_.]+/?\w[-\w_.]*\.)?[a-z]+(?:/[-\w_.%]+)*\b(?!\.))",
|
|
"",
|
|
text,
|
|
)
|
|
with self._mutex:
|
|
return self._speech(text, voice_index)
|
|
|
|
@abc.abstractmethod
|
|
def _setup(self) -> None:
|
|
"""
|
|
Setup the voices, API key, etc.
|
|
"""
|
|
|
|
@abc.abstractmethod
|
|
def _speech(self, text: str, voice_index: int = 0) -> bool:
|
|
"""
|
|
Play the given text.
|
|
|
|
Args:
|
|
text (str): The text to play.
|
|
"""
|