Skip to content

Need to replace ElevenLabs with Edge-TTS #160

Closed Answered by rany2
rajtilakjee asked this question in Q&A
Discussion options

You must be logged in to vote

Return audio_segment inside the try scope. It will still execute the finally:

import asyncio
import edge_tts
from pydub import AudioSegment

VOICE = "en-GB-SoniaNeural"

def convert_text_to_mp3(text):
    loop = asyncio.get_event_loop_policy().get_event_loop()
    try:
        audio_segment = loop.run_until_complete(edge_tts.Communicate(text, VOICE))
        return audio_segment
    finally:
        loop.close()

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@rany2
Comment options

Answer selected by rajtilakjee
@rany2
Comment options

@rajtilakjee
Comment options

@rany2
Comment options

@rajtilakjee
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants