parent
01501ac2ad
commit
ec580fa60e
@ -1,10 +1,10 @@
|
|||||||
from swarms import OpenAITTS
|
from swarms import OpenAITTS
|
||||||
|
|
||||||
tts = OpenAITTS(
|
tts = OpenAITTS(
|
||||||
model_name = "tts-1-1106",
|
model_name="tts-1-1106",
|
||||||
voice = "onyx",
|
voice="onyx",
|
||||||
openai_api_key="sk"
|
openai_api_key="YOUR_API_KEY",
|
||||||
)
|
)
|
||||||
|
|
||||||
out = tts("Hello world")
|
out = tts.run_and_save("pliny is a girl and a chicken")
|
||||||
print(out)
|
print(out)
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
import wave
|
||||||
|
from typing import Optional
|
||||||
|
from swarms.models.base_llm import AbstractLLM
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTTSModel(AbstractLLM):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
model_name,
|
||||||
|
voice,
|
||||||
|
chunk_size,
|
||||||
|
save_to_file: bool = False,
|
||||||
|
saved_filepath: Optional[str] = None,
|
||||||
|
):
|
||||||
|
self.model_name = model_name
|
||||||
|
self.voice = voice
|
||||||
|
self.chunk_size = chunk_size
|
||||||
|
|
||||||
|
def save(self, filepath: Optional[str] = None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def load(self, filepath: Optional[str] = None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def run(self, task: str, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def save_to_file(self, speech_data, filename):
|
||||||
|
"""Save the speech data to a file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
speech_data (bytes): The speech data.
|
||||||
|
filename (str): The path to the file where the speech will be saved.
|
||||||
|
"""
|
||||||
|
with wave.open(filename, "wb") as file:
|
||||||
|
file.setnchannels(1)
|
||||||
|
file.setsampwidth(2)
|
||||||
|
file.setframerate(22050)
|
||||||
|
file.writeframes(speech_data)
|
Loading…
Reference in new issue