Repo Begin
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
import asyncio, edge_tts, random
|
||||
from edge_tts import VoicesManager
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
async def generate(text, voice, rate="+0%", volume="+0%", pitch="+0Hz") -> None:
|
||||
communicate = edge_tts.Communicate(f"{text}",
|
||||
f"{voice}",
|
||||
rate=f"{rate}",
|
||||
volume=f"{volume}",
|
||||
pitch=f"{pitch}"
|
||||
)
|
||||
await communicate.save(OUTPUT_FILE)
|
||||
|
||||
async def generate_select_voice(gender, language) -> None:
|
||||
voices = await VoicesManager.create()
|
||||
voice = voices.find(Gender=f"{gender}", Language=f"{language}")
|
||||
# Also supports Locales
|
||||
# voice = voices.find(Gender="Female", Locale="es-AR")
|
||||
|
||||
communicate = edge_tts.Communicate(TEXTO, random.choice(voice)["Name"])
|
||||
await communicate.save(OUTPUT_FILE)
|
||||
|
||||
async def stream(text, voice) -> None:
|
||||
communicate = edge_tts.Communicate(f"{text}", f"{voice}")
|
||||
with open(OUTPUT_FILE, "wb") as file:
|
||||
async for chunk in communicate.stream():
|
||||
if chunk["type"] == "audio":
|
||||
file.write(chunk["data"])
|
||||
elif chunk["type"] == "WordBoundary":
|
||||
print(f"WordBoundary: {chunk}")
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
VOICE_MALE_PTBR = "pt-BR-AntonioNeural"
|
||||
VOICE_FEMALE_PTBR = "pt-BR-FranciscaNeural"
|
||||
OUTPUT_FILE = "output.mp3"
|
||||
|
||||
TEXTO = "Olá, seja bem vindo!"
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#asyncio.run(generate(TEXTO, VOICE_MALE_PTBR))
|
||||
Reference in New Issue
Block a user