adi-123 commited on
Commit
5d9279e
·
verified ·
1 Parent(s): b234ec5

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +10 -6
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
- audio_model = pipeline("text-to-speech", model="myshell-ai/MeloTTS-English")
53
- speech = captioning_model(text, max_new_tokens=200)[0]["generated_speech"]
54
- return speech
 
 
 
 
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]: