computing phoneme/word variant for each word in a phrase
parent
b4ceeb4eed
commit
1f19463b65
|
|
@ -124,13 +124,18 @@ def parse_apple_phonemes(ph_str):
|
|||
return []
|
||||
|
||||
|
||||
def similar_phoneme(ph_str):
|
||||
def similar_phoneme_word(ph_str):
|
||||
phons = parse_apple_phonemes(ph_str)
|
||||
vowels = [i for i in phons if i.vowel]
|
||||
random.choice(vowels).adjust_stress()
|
||||
return ''.join([str(i) for i in phons])
|
||||
|
||||
def similar_phoneme_phrase(ph_str):
|
||||
return ' '.join([similar_phoneme_word(w) for w in ph_str.split()])
|
||||
|
||||
def similar_word(word_str):
|
||||
similar = pronouncing.rhymes(word_str)
|
||||
return random.choice(similar) if len(similar) > 0 else word_str
|
||||
|
||||
def similar_phrase(ph_str):
|
||||
return ' '.join([similar_word(w) for w in ph_str.split()])
|
||||
|
|
|
|||
|
|
@ -7,14 +7,20 @@ import random
|
|||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
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 = 'go_home'
|
||||
dest_dir = os.path.abspath('.') + '/outputs/' + OUTPUT_NAME + '/'
|
||||
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):
|
||||
widgets = [title, progressbar.Counter(), 'th entry - ', progressbar.FormatLabel(
|
||||
|
|
@ -104,28 +110,28 @@ class SynthVariant(object):
|
|||
orig_phon = self.synth.phonemesFromText_('water')
|
||||
return orig_phon != ''
|
||||
|
||||
def generate_audio(self, word, variant):
|
||||
def generate_audio(self, text, variant):
|
||||
orig_phon, phoneme, phon_cmd = self.synth.phonemesFromText_(
|
||||
word), '', word
|
||||
text), '', text
|
||||
if variant == 'low':
|
||||
# self.synth.startSpeakingString_toURL_(word,d_url)
|
||||
phoneme = orig_phon
|
||||
elif variant == 'medium':
|
||||
phoneme = similar_phoneme(orig_phon)
|
||||
phoneme = similar_phoneme_phrase(orig_phon)
|
||||
phon_cmd = '[[inpt PHON]] ' + phoneme
|
||||
elif variant == 'high':
|
||||
phoneme = similar_word(word)
|
||||
phoneme = similar_phrase(text)
|
||||
phon_cmd = phoneme
|
||||
# elif variant == 'long':
|
||||
# if phon != '':
|
||||
# self.phone_synth.startSpeakingString_toURL_(phon,d_url)
|
||||
# else:
|
||||
# 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_url = NSURL.fileURLWithPath_(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):
|
||||
if self.phoneme_capable:
|
||||
|
|
@ -170,6 +176,7 @@ def synth_generator():
|
|||
print('Discarding phoneme incapable ', s)
|
||||
|
||||
def synth_for_words(words, writer):
|
||||
start_time = time.time()
|
||||
prog_title = "Synthesizing {} words : ".format(len(words))
|
||||
for s in voice_synths:
|
||||
s.create_synth_dirs()
|
||||
|
|
@ -179,6 +186,9 @@ def synth_generator():
|
|||
update('"{}" with {} variant ({})'.format(w, s, v))
|
||||
synthed = s.generate_audio(w, v)
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -215,9 +225,9 @@ def synth_logger(fname, csv=False):
|
|||
|
||||
def generate_audio_for_text_list(text_list):
|
||||
(writer, closer) = synth_logger(dest_file, csv=True)
|
||||
synth_for_words = synth_generator()
|
||||
synth_for_texts = synth_generator()
|
||||
try:
|
||||
synth_for_words(text_list, writer)
|
||||
synth_for_texts(text_list, writer)
|
||||
except:
|
||||
import traceback
|
||||
import sys
|
||||
|
|
@ -230,18 +240,19 @@ def generate_audio_for_stories():
|
|||
story_file = './inputs/all_stories.json'
|
||||
stories_data = json.load(open(story_file))
|
||||
# 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]
|
||||
(writer, closer) = synth_logger(dest_file, csv=True)
|
||||
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()
|
||||
text_list = [i for g in stories_data.values() for i in g]
|
||||
generate_audio_for_text_list(text_list)
|
||||
# (writer, closer) = synth_logger(dest_file, csv=True)
|
||||
# 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__':
|
||||
generate_audio_for_text_list(['random','education'])
|
||||
generate_audio_for_text_list(['I want to go home','education'])
|
||||
# generate_audio_for_stories()
|
||||
|
|
|
|||
Loading…
Reference in New Issue