catiR commited on
Commit
07c85d3
1 Parent(s): a4ed697

adjust plot

Browse files
Files changed (2) hide show
  1. scripts/clusterprosody.py +35 -15
  2. scripts/runSQ.py +2 -2
scripts/clusterprosody.py CHANGED
@@ -222,14 +222,22 @@ def match_tts(clusters, speech_data, tts_data, tts_align, words, seg_aligns, voi
222
  bad_data = {f'{words}**{r}': speech_data[f'{words}**{r}'] for r,c in clusters if c==bad_cluster}
223
 
224
  #tts_fig_p = plot_pitch_tts(matched_data,tts_data, tts_align, words,seg_aligns,best_cluster,voice)
225
- tts_fig_p = plot_one_cluster(words,'pitch',matched_data,seg_aligns,best_cluster,tts_data=tts_data,tts_align=tts_align,voice=voice)
226
- fig_mid_p = plot_one_cluster(words,'pitch',mid_data,seg_aligns,mid_cluster)
227
- fig_bad_p = plot_one_cluster(words,'pitch',bad_data,seg_aligns,bad_cluster)
228
 
229
 
230
- tts_fig_e = plot_one_cluster(words,'rmse',matched_data,seg_aligns,best_cluster,tts_data=tts_data,tts_align=tts_align,voice=voice)
231
- fig_mid_e = plot_one_cluster(words,'rmse',mid_data,seg_aligns,mid_cluster)
232
- fig_bad_e = plot_one_cluster(words,'rmse',bad_data,seg_aligns,bad_cluster)
 
 
 
 
 
 
 
 
233
 
234
  return best_cluster_score, tts_fig_p, fig_mid_p, fig_bad_p, tts_fig_e, fig_mid_e, fig_bad_e
235
 
@@ -298,18 +306,27 @@ def cluster(norm_sent,orig_sent,h_spk_ids, h_align_dir, h_f0_dir, h_wav_dir, tts
298
 
299
 
300
 
 
 
 
 
 
 
301
  # realign at the start of each word
302
  # destroys pause information but overall more legible
303
  def reset_cluster_times(words,cluster_speakers,human_aligns,tts_align):
304
  words = words.split('_')
305
- retimes = []
306
- for i in range(len(words)):
307
- starts = [human_aligns[spk][i][1] for spk in cluster_speakers]
 
 
308
  if tts_align:
309
- starts.append(tts_align[i][1])
310
- retimes.append((words[i],max(starts)))
311
  return retimes
312
 
 
313
  def retime_speaker_xvals(retimes, speaker_aligns, speaker_xvals):
314
  new_xvals = []
315
  def xlim(x,i,retimes,speaker_aligns):
@@ -321,7 +338,7 @@ def retime_speaker_xvals(retimes, speaker_aligns, speaker_xvals):
321
  xdiff = st-s
322
  new_xvals += [x+xdiff for x in speaker_xvals if (x>= s) and xlim(x,i,retimes,speaker_aligns) ]
323
 
324
- return [round(x,2) for x in new_xvals]
325
 
326
 
327
 
@@ -329,6 +346,7 @@ def plot_one_cluster(words,feature,speech_data,seg_aligns,cluster_id,tts_data=No
329
  #(speech_data, tts_data, tts_align, words, seg_aligns, cluster_id, voice):
330
  colors = ["red", "green", "blue", "orange", "purple", "pink", "brown", "gray", "cyan"]
331
  cc = 0
 
332
  fig = plt.figure(figsize=(10, 5))
333
 
334
  if feature.lower() in ['pitch','f0']:
@@ -341,7 +359,7 @@ def plot_one_cluster(words,feature,speech_data,seg_aligns,cluster_id,tts_data=No
341
  pfunc = plt.plot
342
  else:
343
  print('problem with the figure')
344
- return fig
345
 
346
 
347
  # boundary for start of each word
@@ -361,6 +379,7 @@ def plot_one_cluster(words,feature,speech_data,seg_aligns,cluster_id,tts_data=No
361
  # datapoint interval is 0.005 seconds
362
  feat_xvals = [x*0.005 for x in range(len(feats))]
363
  feat_xvals = retime_speaker_xvals(retimes, word_times, feat_xvals)
 
364
 
365
 
366
  #pfunc(feat_xvals, feats, color=colors[cc], label=f"Speaker {spk}")
@@ -371,7 +390,8 @@ def plot_one_cluster(words,feature,speech_data,seg_aligns,cluster_id,tts_data=No
371
  feat_xvals = feat_xvals[:-(len(w_xvals))]
372
  feats = feats[:-(len(w_xvals))]
373
 
374
-
 
375
  cc += 1
376
  if cc >= len(colors):
377
  cc=0
@@ -393,7 +413,7 @@ def plot_one_cluster(words,feature,speech_data,seg_aligns,cluster_id,tts_data=No
393
  #plt.show()
394
 
395
 
396
- return fig
397
 
398
 
399
 
 
222
  bad_data = {f'{words}**{r}': speech_data[f'{words}**{r}'] for r,c in clusters if c==bad_cluster}
223
 
224
  #tts_fig_p = plot_pitch_tts(matched_data,tts_data, tts_align, words,seg_aligns,best_cluster,voice)
225
+ tts_fig_p, best_cc = plot_one_cluster(words,'pitch',matched_data,seg_aligns,best_cluster,tts_data=tts_data,tts_align=tts_align,voice=voice)
226
+ fig_mid_p, mid_cc = plot_one_cluster(words,'pitch',mid_data,seg_aligns,mid_cluster)
227
+ fig_bad_p, bad_cc = plot_one_cluster(words,'pitch',bad_data,seg_aligns,bad_cluster)
228
 
229
 
230
+ tts_fig_e, _ = plot_one_cluster(words,'rmse',matched_data,seg_aligns,best_cluster,tts_data=tts_data,tts_align=tts_align,voice=voice)
231
+ fig_mid_e, _ = plot_one_cluster(words,'rmse',mid_data,seg_aligns,mid_cluster)
232
+ fig_bad_e, _ = plot_one_cluster(words,'rmse',bad_data,seg_aligns,bad_cluster)
233
+
234
+
235
+ # TODO
236
+ # not necessarily here, bc paths to audio files.
237
+ spk_cc_map = [('Best',best_cluster,best_cc), ('Mid',mid_cluster,mid_cc), ('Last',bad_cluster,bad_cc)]
238
+ print(spk_cc_map)
239
+ #playable = audio_htmls(spk_cc_map)
240
+
241
 
242
  return best_cluster_score, tts_fig_p, fig_mid_p, fig_bad_p, tts_fig_e, fig_mid_e, fig_bad_e
243
 
 
306
 
307
 
308
 
309
+
310
+
311
+ # TODO:
312
+ # redo this so that it doesnt just take the max Start Time of each word ;
313
+ # but, in effect,
314
+ # finds the max Duration of the 1st word, the max Duration of the next, and so on.
315
  # realign at the start of each word
316
  # destroys pause information but overall more legible
317
  def reset_cluster_times(words,cluster_speakers,human_aligns,tts_align):
318
  words = words.split('_')
319
+
320
+ retimes = [(words[0], 0.0)]
321
+ for i in range(len(words)-1):
322
+ #starts = [human_aligns[spk][i][1] for spk in cluster_speakers]
323
+ gaps = [human_aligns[spk][i+1][1]-human_aligns[spk][i][1] for spk in cluster_speakers]
324
  if tts_align:
325
+ gaps.append(tts_align[i+1][1] - tts_align[i][1])
326
+ retimes.append((words[i+1],retimes[i][1]+max(gaps)))
327
  return retimes
328
 
329
+
330
  def retime_speaker_xvals(retimes, speaker_aligns, speaker_xvals):
331
  new_xvals = []
332
  def xlim(x,i,retimes,speaker_aligns):
 
338
  xdiff = st-s
339
  new_xvals += [x+xdiff for x in speaker_xvals if (x>= s) and xlim(x,i,retimes,speaker_aligns) ]
340
 
341
+ return [round(x,3) for x in new_xvals]
342
 
343
 
344
 
 
346
  #(speech_data, tts_data, tts_align, words, seg_aligns, cluster_id, voice):
347
  colors = ["red", "green", "blue", "orange", "purple", "pink", "brown", "gray", "cyan"]
348
  cc = 0
349
+ spk_ccs = [] # for external display
350
  fig = plt.figure(figsize=(10, 5))
351
 
352
  if feature.lower() in ['pitch','f0']:
 
359
  pfunc = plt.plot
360
  else:
361
  print('problem with the figure')
362
+ return fig, []
363
 
364
 
365
  # boundary for start of each word
 
379
  # datapoint interval is 0.005 seconds
380
  feat_xvals = [x*0.005 for x in range(len(feats))]
381
  feat_xvals = retime_speaker_xvals(retimes, word_times, feat_xvals)
382
+
383
 
384
 
385
  #pfunc(feat_xvals, feats, color=colors[cc], label=f"Speaker {spk}")
 
390
  feat_xvals = feat_xvals[:-(len(w_xvals))]
391
  feats = feats[:-(len(w_xvals))]
392
 
393
+
394
+ spk_ccs.append((spk,colors[cc]))
395
  cc += 1
396
  if cc >= len(colors):
397
  cc=0
 
413
  #plt.show()
414
 
415
 
416
+ return fig, spk_ccs
417
 
418
 
419
 
scripts/runSQ.py CHANGED
@@ -222,11 +222,11 @@ def setup_tts_sent(sentence,ttsdir,meta_path = 'tts_meta.tsv'):
222
 
223
 
224
  def localtest():
225
- sentence = 'Ef svo er, hvað heita þau þá?'#'Var það ekki nóg?'
226
  voices = ['Alfur_v2'] #,'Dilja']
227
  # make for now the interface allows max one voice
228
 
229
- start_end_word_ix = '5-7'
230
 
231
  locl = '/home/caitlinr/work/peval/pce/'
232
  corpus_meta = locl+'human_data/SQL1adult10s_metadata.tsv'
 
222
 
223
 
224
  def localtest():
225
+ sentence = 'En er hægt að taka orðalagið bókstaflega?'#'Ef svo er, hvað heita þau þá?'#'Var það ekki nóg?'
226
  voices = ['Alfur_v2'] #,'Dilja']
227
  # make for now the interface allows max one voice
228
 
229
+ start_end_word_ix = '1-3'#'5-7'
230
 
231
  locl = '/home/caitlinr/work/peval/pce/'
232
  corpus_meta = locl+'human_data/SQL1adult10s_metadata.tsv'