| import json | |
| def get_sample(): | |
| with open("bg3.ndjson", "r") as bg3_f: | |
| for line in bg3_f: | |
| yield json.loads(line.strip()) | |
| def main(): | |
| speaker_stats = {} | |
| total_duration = 0.0 | |
| total_num_samples = 0 | |
| for metadata in get_sample(): | |
| total_num_samples+=1 | |
| duration = metadata["duration"] | |
| total_duration += duration | |
| spk_id = metadata["spk_id"] | |
| if spk_id not in speaker_stats.keys(): | |
| speaker_stats[spk_id] = dict(num_samples=0, total_duration=0) | |
| speaker_stats[spk_id]["num_samples"] += 1 | |
| speaker_stats[spk_id]["total_duration"] += duration | |
| for spk_id in speaker_stats.keys(): | |
| speaker_stats[spk_id]["mean_duration"] = speaker_stats[spk_id]["total_duration"]/speaker_stats[spk_id]["num_samples"] | |
| speaker_stats["global"] = dict( | |
| num_samples=total_num_samples, | |
| total_duration=total_duration, | |
| mean_duration=total_duration/len(speaker_stats) | |
| ) | |
| print(json.dumps(speaker_stats, indent=2)) | |
| if __name__=="__main__": | |
| main() | |