Skip to content

Commit

Permalink
Merge pull request #20 from Music-and-Culture-Technology-Lab/hotfix
Browse files Browse the repository at this point in the history
Hotfix version
  • Loading branch information
BreezeWhite authored May 7, 2021
2 parents bc73b10 + b650ca0 commit e2c66f5
Show file tree
Hide file tree
Showing 6 changed files with 870 additions and 749 deletions.
8 changes: 7 additions & 1 deletion omnizart/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ def write_agg_f0_results(agg_f0, output_path):
omnizart.utils.aggregate_f0_info:
The function for generating the aggregated F0 information.
"""
fieldnames = ["start_time", "end_time", "frequency", "pitch"]

# Check the format is correct
if any(list(row.keys()) != fieldnames for row in agg_f0):
raise ValueError(f"Fields inconsistent! Expected: {fieldnames}")

with open(output_path, "w") as out:
writer = csv.DictWriter(out, fieldnames=["start_time", "end_time", "frequency"])
writer = csv.DictWriter(out, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(agg_f0)
3 changes: 3 additions & 0 deletions omnizart/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def aggregate_f0_info(pred, t_unit):
start_idx = 0
last_hz = pred[0]
eps = 1e-6
pred.append(0) # Append an additional zero to the end temporarily.
while cur_idx < len(pred):
cur_hz = pred[cur_idx]
if abs(cur_hz - last_hz) < eps:
Expand All @@ -388,4 +389,6 @@ def aggregate_f0_info(pred, t_unit):
start_idx = cur_idx
cur_idx += 1
last_hz = cur_hz

del pred[-1] # Remove the additional ending zero.
return results
Loading

0 comments on commit e2c66f5

Please sign in to comment.