adi-123 commited on
Commit
b234ec5
·
verified ·
1 Parent(s): 5350da8

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +5 -9
utils.py CHANGED
@@ -46,16 +46,12 @@ 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) -> None:
50
  print("Initializing text-to-speech conversion...")
51
- API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
52
- headers = {"Authorization": f"Bearer {os.environ['HUGGINGFACEHUB_API_TOKEN']}"}
53
- payloads = {'inputs': text}
54
-
55
- response = requests.post(API_URL, headers=headers, json=payloads)
56
-
57
- with open('audio_story.mp3', 'wb') as file:
58
- file.write(response.content)
59
 
60
  # Get user preferences for the story
61
  def get_user_preferences() -> Dict[str, 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]: