51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
import voicerss_tts
|
|
import json
|
|
from speech_tools import format_filename
|
|
|
|
def generate_voice(phrase):
|
|
voice = voicerss_tts.speech({
|
|
'key': '0ae89d82aa78460691c99a4ac8c0f9ec',
|
|
'hl': 'en-us',
|
|
'src': phrase,
|
|
'r': '0',
|
|
'c': 'mp3',
|
|
'f': '22khz_16bit_mono',
|
|
'ssml': 'false',
|
|
'b64': 'false'
|
|
})
|
|
if not voice['error']:
|
|
return voice[b'response']
|
|
return None
|
|
|
|
|
|
def generate_test_audio_for_stories():
|
|
story_file = './inputs/all_stories_hs.json'
|
|
# story_file = './inputs/all_stories.json'
|
|
stories_data = json.load(open(story_file))
|
|
text_list_dup = [t[0] for i in stories_data.values() for t in i]
|
|
text_list = sorted(list(set(text_list_dup)))[:10]
|
|
for t in text_list:
|
|
v = generate_voice(t)
|
|
if v:
|
|
f_name = format_filename(t)
|
|
tf = open('inputs/voicerss/'+f_name+'.mp3','wb')
|
|
tf.write(v)
|
|
tf.close()
|
|
|
|
# def generate_test_audio_for(records_file,audio_group='audio'):
|
|
# # audio_group='audio';model_file = 'siamese_speech_model-305-epoch-0.20-acc.h5'
|
|
# # records_file = os.path.join('./outputs',eval_group+'.train.tfrecords')
|
|
# const_file = os.path.join('./models/'+audio_group+'/','constants.pkl')
|
|
# (n_spec,n_features,n_records) = pickle.load(open(const_file,'rb'))
|
|
# print('evaluating {}...'.format(records_file))
|
|
# record_iterator,records_count = record_generator_count(records_file)
|
|
# all_results = []
|
|
# for (i,string_record) in tqdm(enumerate(record_iterator),total=records_count):
|
|
# total+=1
|
|
# example = tf.train.Example()
|
|
# example.ParseFromString(string_record)
|
|
# word = example.features.feature['word'].bytes_list.value[0].decode()
|
|
|
|
# audio = generate_voice('hello world')
|
|
# audio
|