<reponame>mchuc/MAM<gh_stars>1-10
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# (C) 2021 <NAME>, marcin at afya.pl
# https://www.datacamp.com/community/tutorials/argument-parsing-in-python?utm_source=adwords_ppc&utm_campaignid=1455363063&utm_adgroupid=65083631748&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=278443377095&utm_targetid=aud-438999696719:dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=9067385&gclid=Cj0KCQjw4eaJBhDMARIsANhrQACpPNNA80rwnzKx7By4a_44shXJmXpg7JYfCUW3Z1zirHkkqZGwSn8aAgdgEALw_wcB
###################### language
LANGUAGE = 'pl' # app language
# voice language - see here:https://codelabs.developers.google.com/codelabs/cloud-text-speech-python3/#7 and here: https://cloud.google.com/text-to-speech -> DEMO

import os.path
import argparse
from tts.tts import tts
from tts.fileTypes import fileType
import gettext
import json
import re


for lang in [LANGUAGE]:
    lang_translations = gettext.translation('base', localedir='locales', languages=[lang])
    lang_translations.install()
    _ = lang_translations.gettext

if not os.path.exists(os.path.join(os.getcwd(),"private")):
    print ("Tworzę", os.path.join(os.getcwd(),"private"))
    os.makedirs(os.path.join(os.getcwd(),"private"))

ap = argparse.ArgumentParser()
ap.add_argument("-j", "--json", required=True,help="json file to process")
ap.add_argument("-a", "--auth-file", required=False,help="google auth file", default= os.path.join(os.getcwd(),'private','api-key.json'))
args = vars(ap.parse_args())

with open(args["json"], encoding='utf-8') as input:
     json_= json.load(input)
exclude_ = re.compile(r'^[^__]',re.UNICODE|re.MULTILINE|re.S) # exclude keys from JSON that begin with __

google_ = tts(args['auth_file'],os.getcwd()) #Google Client

voice_ =json_['__voice'] if '__voice' in json_  else 'en-US-WaveNet-A'
speed_ =json_['__speed'] if '__speed' in json_  else 1.0
output_path_ = json_['__output_path'] if '__output_path' in json_  else 'output'
output_path_is_absotule_ = json_['__output_path_is_absotule'] if '__output_path_is_absotule' in json_  else False

if output_path_is_absotule_:
    if not os.path.exists(os.path.join(os.getcwd(),output_path_)):
        os.makedirs(os.path.join(os.getcwd(),output_path_))
else:
    if not os.path.exists(os.path.join(output_path_)):
        os.makedirs(os.path.join(output_path_))

if '__file_type' in json_:
    if json_["__file_type"].lower() =="wav":
        fT=fileType.WAV
    elif json_["__file_type"].lower() =="mp3":
        fT=fileType.MP3
    else:
        print("Audio file result type not specified or incorrectly specified (entry missing: __file_type in the JSON sight file")
        exit(2)

for key in json_:
    if exclude_.match(key):
        val = json_[key]
        print ("Generating voice ... ", key, ' => ', val )
        r = google_.text_to_voice(voice_,val, speed_, fileType.WAV,key, output_path_,output_path_is_absotule_,False)

## conversion

if fT==fileType.WAV:
    for key in json_:
        if exclude_.match(key):
            file_name_in = google_.get_filename(key,fT,output_path_,output_path_is_absotule_,True)
            file_name_out_ulaw = google_.get_filename(key,fileType.ULAW,output_path_,output_path_is_absotule_,True)
            file_name_out_alaw = google_.get_filename(key,fileType.ALAW,output_path_,output_path_is_absotule_,True)
            file_name_out_gsm = google_.get_filename(key,fileType.GSM,output_path_,output_path_is_absotule_,True)
            command1 = ("sox -V \"%s\" -r 8000 -c 1 -t ul \"%s\"")%(file_name_in,file_name_out_ulaw)
            command2 = ("sox -V \"%s\" -r 8000 -c 1 -t al \"%s\"")%(file_name_in,file_name_out_alaw)
            command3 = ("sox -V \"%s\" -r 8000 -c 1 -t gsm \"%s\"")%(file_name_in,file_name_out_gsm)
            print ("Converting [ULAW]", file_name_in," to ",file_name_out_ulaw)
            os.system(command1)
            print ("Converting [ALAW]", file_name_in," to ",file_name_out_alaw)
            os.system(command2)
            print ("Converting [GSM]", file_name_in," to ",file_name_out_gsm)
            os.system(command3)


#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# (C) 2021 <NAME>, marcin at afya.pl
# https://www.datacamp.com/community/tutorials/argument-parsing-in-python?utm_source=adwords_ppc&utm_campaignid=1455363063&utm_adgroupid=65083631748&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=278443377095&utm_targetid=aud-438999696719:dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=9067385&gclid=Cj0KCQjw4eaJBhDMARIsANhrQACpPNNA80rwnzKx7By4a_44shXJmXpg7JYfCUW3Z1zirHkkqZGwSn8aAgdgEALw_wcB
###################### language
LANGUAGE = 'pl' # app language
# voice language - see here:https://codelabs.developers.google.com/codelabs/cloud-text-speech-python3/#7 and here: https://cloud.google.com/text-to-speech -> DEMO

import os.path
import argparse
from tts.tts import tts
from tts.fileTypes import fileType
import gettext
import json
import re


for lang in [LANGUAGE]:
    lang_translations = gettext.translation('base', localedir='locales', languages=[lang])
    lang_translations.install()
    _ = lang_translations.gettext

if not os.path.exists(os.path.join(os.getcwd(),"private")):
    print ("Tworzę", os.path.join(os.getcwd(),"private"))
    os.makedirs(os.path.join(os.getcwd(),"private"))

ap = argparse.ArgumentParser()
ap.add_argument("-j", "--json", required=True,help="json file to process")
ap.add_argument("-a", "--auth-file", required=False,help="google auth file", default= os.path.join(os.getcwd(),'private','api-key.json'))
args = vars(ap.parse_args())

with open(args["json"], encoding='utf-8') as input:
     json_= json.load(input)
exclude_ = re.compile(r'^[^__]',re.UNICODE|re.MULTILINE|re.S) # exclude keys from JSON that begin with __

google_ = tts(args['auth_file'],os.getcwd()) #Google Client

voice_ =json_['__voice'] if '__voice' in json_  else 'en-US-WaveNet-A'
speed_ =json_['__speed'] if '__speed' in json_  else 1.0
output_path_ = json_['__output_path'] if '__output_path' in json_  else 'output'
output_path_is_absotule_ = json_['__output_path_is_absotule'] if '__output_path_is_absotule' in json_  else False

if output_path_is_absotule_:
    if not os.path.exists(os.path.join(os.getcwd(),output_path_)):
        os.makedirs(os.path.join(os.getcwd(),output_path_))
else:
    if not os.path.exists(os.path.join(output_path_)):
        os.makedirs(os.path.join(output_path_))

if '__file_type' in json_:
    if json_["__file_type"].lower() =="wav":
        fT=fileType.WAV
    elif json_["__file_type"].lower() =="mp3":
        fT=fileType.MP3
    else:
        print("Audio file result type not specified or incorrectly specified (entry missing: __file_type in the JSON sight file")
        exit(2)

for key in json_:
    if exclude_.match(key):
        val = json_[key]
        print ("Generating voice ... ", key, ' => ', val )
        r = google_.text_to_voice(voice_,val, speed_, fileType.WAV,key, output_path_,output_path_is_absotule_,False)

## conversion

if fT==fileType.WAV:
    for key in json_:
        if exclude_.match(key):
            file_name_in = google_.get_filename(key,fT,output_path_,output_path_is_absotule_,True)
            file_name_out_ulaw = google_.get_filename(key,fileType.ULAW,output_path_,output_path_is_absotule_,True)
            file_name_out_alaw = google_.get_filename(key,fileType.ALAW,output_path_,output_path_is_absotule_,True)
            file_name_out_gsm = google_.get_filename(key,fileType.GSM,output_path_,output_path_is_absotule_,True)
            command1 = ("sox -V \"%s\" -r 8000 -c 1 -t ul \"%s\"")%(file_name_in,file_name_out_ulaw)
            command2 = ("sox -V \"%s\" -r 8000 -c 1 -t al \"%s\"")%(file_name_in,file_name_out_alaw)
            command3 = ("sox -V \"%s\" -r 8000 -c 1 -t gsm \"%s\"")%(file_name_in,file_name_out_gsm)
            print ("Converting [ULAW]", file_name_in," to ",file_name_out_ulaw)
            os.system(command1)
            print ("Converting [ALAW]", file_name_in," to ",file_name_out_alaw)
            os.system(command2)
            print ("Converting [GSM]", file_name_in," to ",file_name_out_gsm)
            os.system(command3)
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- # (C) 2021 <NAME>, marcin at afya.pl # https://www.datacamp.com/community/tutorials/argument-parsing-in-python?utm_source=adwords_ppc&utm_campaignid=1455363063&utm_adgroupid=65083631748&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=278443377095&utm_targetid=aud-438999696719:dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=9067385&gclid=Cj0KCQjw4eaJBhDMARIsANhrQACpPNNA80rwnzKx7By4a_44shXJmXpg7JYfCUW3Z1zirHkkqZGwSn8aAgdgEALw_wcB ###################### language # app language # voice language - see here:https://codelabs.developers.google.com/codelabs/cloud-text-speech-python3/#7 and here: https://cloud.google.com/text-to-speech -> DEMO # exclude keys from JSON that begin with __ #Google Client ## conversion