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 []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def similar_phoneme(ph_str):
|
def similar_phoneme_word(ph_str):
|
||||||
phons = parse_apple_phonemes(ph_str)
|
phons = parse_apple_phonemes(ph_str)
|
||||||
vowels = [i for i in phons if i.vowel]
|
vowels = [i for i in phons if i.vowel]
|
||||||
random.choice(vowels).adjust_stress()
|
random.choice(vowels).adjust_stress()
|
||||||
return ''.join([str(i) for i in phons])
|
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):
|
def similar_word(word_str):
|
||||||
similar = pronouncing.rhymes(word_str)
|
similar = pronouncing.rhymes(word_str)
|
||||||
return random.choice(similar) if len(similar) > 0 else 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 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 = 'go_home'
|
||||||
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,19 @@ 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 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()
|
# (writer, closer) = synth_logger(dest_file, csv=True)
|
||||||
try:
|
# synth_for_words = synth_generator()
|
||||||
synth_for_words(word_list, writer)
|
# try:
|
||||||
except:
|
# synth_for_words(word_list, writer)
|
||||||
import traceback
|
# except:
|
||||||
import sys
|
# import traceback
|
||||||
traceback.print_exc(file=sys.stdout)
|
# import sys
|
||||||
pass
|
# traceback.print_exc(file=sys.stdout)
|
||||||
closer()
|
# 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()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue