File size: 1,151 Bytes
e6b8403
 
 
 
 
fc97911
 
e6b8403
 
 
fc97911
 
 
 
 
 
 
 
 
e6b8403
fc97911
e6b8403
 
 
fc97911
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from gtts import gTTS
import edge_tts
import asyncio
import nest_asyncio

def make_voice(tts_text, tts_voice, filename,language):
    #print(tts_text, filename)
    try:
      nest_asyncio.apply()
      asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save(filename))
    except:
      try:
          tts = gTTS(tts_text, lang=language)
          tts.save(filename)
          print(f'No audio was received. Please change the tts voice for {tts_voice}. USING gTTS.')
      except:
        tts = gTTS('a', lang=language)
        tts.save(filename)
        print('Error: Audio will be replaced.')

def make_voice_gradio(tts_text, tts_voice, filename, language):
    print(tts_text, filename)
    try:
      asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save(filename))
    except:
      try:
        tts = gTTS(tts_text, lang=language)
        tts.save(filename)
        print(f'No audio was received. Please change the tts voice for {tts_voice}. USING gTTS.')
      except:
        tts = gTTS('a', lang=language)
        tts.save(filename)
        print('Error: Audio will be replaced.')