Spaces:
Running
Running
| import os | |
| from gtts import gTTS | |
| import json | |
| def text_to_speech(text, lang, dest): | |
| speech = gTTS(text=text, lang=lang) | |
| speech.save(dest) | |
| def generate_audio_files(): | |
| with open('static/data/displaytext.json', 'r', encoding='utf-8') as file: | |
| data = json.load(file) | |
| for key, value in data.items(): | |
| ind = 0 | |
| if not os.path.exists(os.path.join("static/audio/languages", key)): | |
| os.makedirs(os.path.join("static/audio/languages", key)) | |
| text_to_speech(value['ask'], value['code'], "static/audio/languages/" + key + "/ask.mp3") | |
| for step in value['steps']: | |
| if ind == 1: | |
| ind += 1 | |
| text_to_speech(step, value['code'], "static/audio/languages/" + key + "/step" + str(ind+1) + ".mp3") | |
| ind += 1 | |
| generate_audio_files() | |
| def create_directories(): | |
| directories = ["static/audio/languages", "static/audio/conclusion", "static/audio/status", "static/audio/doyoumean", "static/assets/plot"] | |
| for directory in directories: | |
| if not os.path.exists(directory): | |
| os.makedirs(directory) | |
| create_directories() |