|
|
|
@ -7,14 +7,20 @@ import random
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import time
|
|
|
|
import progressbar
|
|
|
|
import progressbar
|
|
|
|
|
|
|
|
|
|
|
|
from generate_similar import similar_phoneme,similar_word
|
|
|
|
from generate_similar import similar_phoneme_phrase,similar_phrase
|
|
|
|
|
|
|
|
|
|
|
|
OUTPUT_NAME = 'rand_edu'
|
|
|
|
OUTPUT_NAME = 'story_all'
|
|
|
|
dest_dir = os.path.abspath('.') + '/outputs/' + OUTPUT_NAME + '/'
|
|
|
|
dest_dir = os.path.abspath('.') + '/outputs/' + OUTPUT_NAME + '/'
|
|
|
|
dest_file = './outputs/' + OUTPUT_NAME + '.csv'
|
|
|
|
dest_file = './outputs/' + OUTPUT_NAME + '.csv'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hms_string(sec_elapsed):
|
|
|
|
|
|
|
|
h = int(sec_elapsed / (60 * 60))
|
|
|
|
|
|
|
|
m = int((sec_elapsed % (60 * 60)) / 60)
|
|
|
|
|
|
|
|
s = sec_elapsed % 60.
|
|
|
|
|
|
|
|
return "{}:{:>02}:{:>05.2f}".format(h, m, s)
|
|
|
|
|
|
|
|
|
|
|
|
def prog_bar(title):
|
|
|
|
def prog_bar(title):
|
|
|
|
widgets = [title, progressbar.Counter(), 'th entry - ', progressbar.FormatLabel(
|
|
|
|
widgets = [title, progressbar.Counter(), 'th entry - ', progressbar.FormatLabel(
|
|
|
|
@ -104,28 +110,28 @@ class SynthVariant(object):
|
|
|
|
orig_phon = self.synth.phonemesFromText_('water')
|
|
|
|
orig_phon = self.synth.phonemesFromText_('water')
|
|
|
|
return orig_phon != ''
|
|
|
|
return orig_phon != ''
|
|
|
|
|
|
|
|
|
|
|
|
def generate_audio(self, word, variant):
|
|
|
|
def generate_audio(self, text, variant):
|
|
|
|
orig_phon, phoneme, phon_cmd = self.synth.phonemesFromText_(
|
|
|
|
orig_phon, phoneme, phon_cmd = self.synth.phonemesFromText_(
|
|
|
|
word), '', word
|
|
|
|
text), '', text
|
|
|
|
if variant == 'low':
|
|
|
|
if variant == 'low':
|
|
|
|
# self.synth.startSpeakingString_toURL_(word,d_url)
|
|
|
|
# self.synth.startSpeakingString_toURL_(word,d_url)
|
|
|
|
phoneme = orig_phon
|
|
|
|
phoneme = orig_phon
|
|
|
|
elif variant == 'medium':
|
|
|
|
elif variant == 'medium':
|
|
|
|
phoneme = similar_phoneme(orig_phon)
|
|
|
|
phoneme = similar_phoneme_phrase(orig_phon)
|
|
|
|
phon_cmd = '[[inpt PHON]] ' + phoneme
|
|
|
|
phon_cmd = '[[inpt PHON]] ' + phoneme
|
|
|
|
elif variant == 'high':
|
|
|
|
elif variant == 'high':
|
|
|
|
phoneme = similar_word(word)
|
|
|
|
phoneme = similar_phrase(text)
|
|
|
|
phon_cmd = phoneme
|
|
|
|
phon_cmd = phoneme
|
|
|
|
# elif variant == 'long':
|
|
|
|
# elif variant == 'long':
|
|
|
|
# if phon != '':
|
|
|
|
# if phon != '':
|
|
|
|
# self.phone_synth.startSpeakingString_toURL_(phon,d_url)
|
|
|
|
# self.phone_synth.startSpeakingString_toURL_(phon,d_url)
|
|
|
|
# else:
|
|
|
|
# else:
|
|
|
|
# self.synth.startSpeakingString_toURL_(word,d_url)
|
|
|
|
# self.synth.startSpeakingString_toURL_(word,d_url)
|
|
|
|
fname = dest_filename(word, self.name, self.rate, variant)
|
|
|
|
fname = dest_filename(text, self.name, self.rate, variant)
|
|
|
|
d_path, r_path = dest_path(self.name, self.rate, fname)
|
|
|
|
d_path, r_path = dest_path(self.name, self.rate, fname)
|
|
|
|
# d_url = NSURL.fileURLWithPath_(d_path)
|
|
|
|
# d_url = NSURL.fileURLWithPath_(d_path)
|
|
|
|
cli_gen_audio(phon_cmd, self.rate, self.name, d_path)
|
|
|
|
cli_gen_audio(phon_cmd, self.rate, self.name, d_path)
|
|
|
|
return SynthFile(word, phoneme, r_path, self.name, self.lang, self.rate, variant)
|
|
|
|
return SynthFile(text, phoneme, r_path, self.name, self.lang, self.rate, variant)
|
|
|
|
|
|
|
|
|
|
|
|
def create_synth_dirs(self):
|
|
|
|
def create_synth_dirs(self):
|
|
|
|
if self.phoneme_capable:
|
|
|
|
if self.phoneme_capable:
|
|
|
|
@ -170,6 +176,7 @@ def synth_generator():
|
|
|
|
print('Discarding phoneme incapable ', s)
|
|
|
|
print('Discarding phoneme incapable ', s)
|
|
|
|
|
|
|
|
|
|
|
|
def synth_for_words(words, writer):
|
|
|
|
def synth_for_words(words, writer):
|
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
prog_title = "Synthesizing {} words : ".format(len(words))
|
|
|
|
prog_title = "Synthesizing {} words : ".format(len(words))
|
|
|
|
for s in voice_synths:
|
|
|
|
for s in voice_synths:
|
|
|
|
s.create_synth_dirs()
|
|
|
|
s.create_synth_dirs()
|
|
|
|
@ -179,6 +186,9 @@ def synth_generator():
|
|
|
|
update('"{}" with {} variant ({})'.format(w, s, v))
|
|
|
|
update('"{}" with {} variant ({})'.format(w, s, v))
|
|
|
|
synthed = s.generate_audio(w, v)
|
|
|
|
synthed = s.generate_audio(w, v)
|
|
|
|
writer(synthed)
|
|
|
|
writer(synthed)
|
|
|
|
|
|
|
|
end_time = time.time()
|
|
|
|
|
|
|
|
time_str = hms_string(end_time - start_time)
|
|
|
|
|
|
|
|
print("It took {} to synthsize all variants.".format(time_str))
|
|
|
|
return synth_for_words
|
|
|
|
return synth_for_words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -215,9 +225,9 @@ def synth_logger(fname, csv=False):
|
|
|
|
|
|
|
|
|
|
|
|
def generate_audio_for_text_list(text_list):
|
|
|
|
def generate_audio_for_text_list(text_list):
|
|
|
|
(writer, closer) = synth_logger(dest_file, csv=True)
|
|
|
|
(writer, closer) = synth_logger(dest_file, csv=True)
|
|
|
|
synth_for_words = synth_generator()
|
|
|
|
synth_for_texts = synth_generator()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
synth_for_words(text_list, writer)
|
|
|
|
synth_for_texts(text_list, writer)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
@ -230,18 +240,9 @@ def generate_audio_for_stories():
|
|
|
|
story_file = './inputs/all_stories.json'
|
|
|
|
story_file = './inputs/all_stories.json'
|
|
|
|
stories_data = json.load(open(story_file))
|
|
|
|
stories_data = json.load(open(story_file))
|
|
|
|
# word_list = [t[0] for i in stories_data.values() for t in i]
|
|
|
|
# word_list = [t[0] for i in stories_data.values() for t in i]
|
|
|
|
word_list = [i for g in stories_data.values() for i in g]
|
|
|
|
text_list = [i.replace('-','') for g in stories_data.values() for i in g]
|
|
|
|
(writer, closer) = synth_logger(dest_file, csv=True)
|
|
|
|
generate_audio_for_text_list(text_list)
|
|
|
|
synth_for_words = synth_generator()
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
synth_for_words(word_list, writer)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
traceback.print_exc(file=sys.stdout)
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
closer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
generate_audio_for_text_list(['random','education'])
|
|
|
|
# generate_audio_for_text_list(['I want to go home','education'])
|
|
|
|
# generate_audio_for_stories()
|
|
|
|
generate_audio_for_stories()
|
|
|
|
|