File size: 1,150 Bytes
829f2ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
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()