Update utils.py
Browse files
utils.py
CHANGED
@@ -46,12 +46,16 @@ def txt2story(prompt: str, top_k: int, top_p: float, temperature: float) -> str:
|
|
46 |
return story
|
47 |
|
48 |
# Text-to-speech
|
49 |
-
def txt2speech(text: str):
|
50 |
-
print("Initializing text-to-speech conversion...")
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
|
56 |
# Get user preferences for the story
|
57 |
def get_user_preferences() -> Dict[str, str]:
|
|
|
46 |
return story
|
47 |
|
48 |
# Text-to-speech
|
49 |
+
def txt2speech(text: str) -> None:
|
50 |
+
print("Initializing MeloTTS text-to-speech conversion...")
|
51 |
+
pipe = pipeline("text-to-speech", model="myshell-ai/MeloTTS-English")
|
52 |
+
|
53 |
+
# Generate audio from the text
|
54 |
+
audio = pipe(text)
|
55 |
+
|
56 |
+
# Save the audio output to a file
|
57 |
+
with open("audio_story.wav", "wb") as file:
|
58 |
+
file.write(audio["wav"])
|
59 |
|
60 |
# Get user preferences for the story
|
61 |
def get_user_preferences() -> Dict[str, str]:
|