fix: fixed language options

pull/534/head
Jason 2 years ago
parent 9859e4a0bc
commit 3778ca2a14

@ -6,37 +6,7 @@ import requests
import sox import sox
from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip from moviepy.audio.AudioClip import concatenate_audioclips, CompositeAudioClip
from moviepy.audio.io.AudioFileClip import AudioFileClip from moviepy.audio.io.AudioFileClip import AudioFileClip
voices = {'neural': [ voices = ['Brian', 'Emma', 'Russell', 'Joey', 'Matthew', 'Joanna', 'Kimberly', 'Amy', 'Geraint', 'Nicole', 'Justin', 'Ivy', 'Kendra', 'Salli', 'Raveena']
'Ivy',
'Joanna',
'Kendra',
'Kimberly',
'Salli',
'Joey',
'Justin',
'Matthew',
'Amy',
'Emma',
'Brian'
], 'standard': [
'Ivy',
'Joanna',
'Kendra',
'Kimberly',
'Salli',
'Joey',
'Justin',
'Matthew',
"Russell",
"Nicole",
"Amy",
"Emma",
"Brian",
"Aditi",
"Raveena",
"Geraint"
]}
# valid voices https://lazypy.ro/tts/ # valid voices https://lazypy.ro/tts/
@ -59,7 +29,7 @@ class POLLY:
if not os.getenv('VOICE'): if not os.getenv('VOICE'):
return ValueError('Please set the environment variable VOICE to a valid voice. options are: {}'.format(voices)) return ValueError('Please set the environment variable VOICE to a valid voice. options are: {}'.format(voices))
voice = str(os.getenv("VOICE")).capitalize() voice = str(os.getenv("VOICE")).capitalize()
body = {'voice': voice, 'text': req_text} body = {'voice': voice, 'text': req_text, 'service': 'polly'}
response = requests.post(self.url, data=body) response = requests.post(self.url, data=body)
try: try:
voice_data = requests.get(response.json()['speak_url']) voice_data = requests.get(response.json()['speak_url'])
@ -76,7 +46,7 @@ class POLLY:
chunkId = 0 chunkId = 0
for chunk in chunks: for chunk in chunks:
body = {'voice': voice, 'text': chunk} body = {'voice': voice, 'text': chunk, 'service': 'polly'}
resp = requests.post(self.url, data=body) resp = requests.post(self.url, data=body)
voice_data = requests.get(resp.json()['speak_url']) voice_data = requests.get(resp.json()['speak_url'])
with open(filename.replace(".mp3", f"-{chunkId}.mp3"), "wb") as out: with open(filename.replace(".mp3", f"-{chunkId}.mp3"), "wb") as out:
@ -111,5 +81,4 @@ class POLLY:
return text return text
def randomvoice(self): def randomvoice(self):
valid = voices['neural'] + voices['standard'] return random.choice(voices)
return random.choice(valid)

Loading…
Cancel
Save