Update utils.py
Browse files
utils.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4 |
from transformers import pipeline
|
5 |
from typing import Dict
|
6 |
from together import Together
|
|
|
7 |
|
8 |
# Image-to-text
|
9 |
def img2txt(url: str) -> str:
|
@@ -47,15 +48,13 @@ def txt2story(prompt: str, top_k: int, top_p: float, temperature: float) -> str:
|
|
47 |
|
48 |
# Text-to-speech
|
49 |
def txt2speech(text: str) -> None:
|
50 |
-
print("
|
51 |
-
pipe = pipeline("text-to-speech", model="myshell-ai/MeloTTS-English")
|
52 |
|
53 |
# Generate audio from the text
|
54 |
-
|
55 |
|
56 |
# Save the audio output to a file
|
57 |
-
|
58 |
-
file.write(audio["wav"])
|
59 |
|
60 |
# Get user preferences for the story
|
61 |
def get_user_preferences() -> Dict[str, str]:
|
|
|
4 |
from transformers import pipeline
|
5 |
from typing import Dict
|
6 |
from together import Together
|
7 |
+
from gtts import gTTS
|
8 |
|
9 |
# Image-to-text
|
10 |
def img2txt(url: str) -> str:
|
|
|
48 |
|
49 |
# Text-to-speech
|
50 |
def txt2speech(text: str) -> None:
|
51 |
+
print("Converting text to speech using gTTS...")
|
|
|
52 |
|
53 |
# Generate audio from the text
|
54 |
+
tts = gTTS(text=text, lang='en')
|
55 |
|
56 |
# Save the audio output to a file
|
57 |
+
tts.save("audio_story.mp3")
|
|
|
58 |
|
59 |
# Get user preferences for the story
|
60 |
def get_user_preferences() -> Dict[str, str]:
|