fix stuff
This commit is contained in:
33
audio/tts.py
Normal file
33
audio/tts.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import asyncio
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
import edge_tts
|
||||
import pygame
|
||||
|
||||
|
||||
def speak(text):
|
||||
async def generate_speech():
|
||||
voice = "en-US-ChristopherNeural"
|
||||
communicate = edge_tts.Communicate(text, voice)
|
||||
await communicate.save(temp_path)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
temp_path = os.path.join(tmpdirname, "speech.mp3")
|
||||
|
||||
asyncio.run(generate_speech())
|
||||
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(temp_path)
|
||||
pygame.mixer.music.play()
|
||||
|
||||
while pygame.mixer.music.get_busy():
|
||||
time.sleep(0.1)
|
||||
|
||||
pygame.mixer.music.unload()
|
||||
pygame.mixer.quit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
speak("Hello! I am now speaking using Microsoft Edge's natural text to speech engine.")
|
||||
Reference in New Issue
Block a user