Datasets:
laubonghaudoi
commited on
Commit
·
06578b0
1
Parent(s):
32adf42
Update stats.py
Browse files
stats.py
CHANGED
@@ -1,8 +1,9 @@
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
-
from requests import get
|
3 |
import torchaudio
|
4 |
-
from datasets import load_dataset
|
5 |
-
from pandas import read_csv
|
6 |
from tqdm import tqdm
|
7 |
|
8 |
|
@@ -14,14 +15,28 @@ def get_audio_length(file_path: str) -> float:
|
|
14 |
return metadata.num_frames / metadata.sample_rate
|
15 |
|
16 |
|
17 |
-
def get_info(
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# List to store individual audio durations
|
21 |
durations = []
|
22 |
total_duration = 0
|
23 |
|
24 |
-
for item in tqdm(dataset
|
25 |
file_path = item['audio']['path']
|
26 |
duration = get_audio_length(file_path)
|
27 |
durations.append(duration)
|
@@ -34,6 +49,7 @@ def get_info(subset):
|
|
34 |
median_duration = np.median(durations)
|
35 |
|
36 |
# Print results
|
|
|
37 |
print(f"Total audio duration: {total_duration / 3600:.2f} hours")
|
38 |
print(f"Total audio duration: {total_duration / 60:.2f} minutes")
|
39 |
print(f"Minimum audio duration: {min_duration:.3f} seconds")
|
@@ -41,8 +57,16 @@ def get_info(subset):
|
|
41 |
print(f"Average audio duration: {avg_duration:.3f} seconds")
|
42 |
print(f"Median audio duration: {median_duration:.3f} seconds")
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Calculate total number of characters
|
48 |
total_characters = metadata['transcription'].str.len().sum()
|
@@ -63,8 +87,10 @@ def get_info(subset):
|
|
63 |
print(f"Number of unique characters: {len(unique_characters)}")
|
64 |
print(f"Unique characters: {''.join(sorted(unique_characters))}")
|
65 |
print(f"Average speech rate: {total_characters / total_duration:.2f} characters per second")
|
|
|
66 |
|
67 |
|
68 |
if __name__ == '__main__':
|
69 |
-
|
70 |
get_info('seoiwuzyun')
|
|
|
|
1 |
+
from typing import List, Literal
|
2 |
+
|
3 |
import numpy as np
|
|
|
4 |
import torchaudio
|
5 |
+
from datasets import concatenate_datasets, load_dataset
|
6 |
+
from pandas import concat, read_csv
|
7 |
from tqdm import tqdm
|
8 |
|
9 |
|
|
|
15 |
return metadata.num_frames / metadata.sample_rate
|
16 |
|
17 |
|
18 |
+
def get_info(subsets: List[str] | Literal["saamgwokjinji", "seoiwuzyun"]) -> None:
|
19 |
+
"""
|
20 |
+
計音頻長度、字數、平均字數、中位數字數、覆蓋字數、平均語速
|
21 |
+
"""
|
22 |
+
if not isinstance(subsets, list):
|
23 |
+
subsets = [subsets]
|
24 |
+
|
25 |
+
datasets = []
|
26 |
+
for subset in subsets:
|
27 |
+
dataset = load_dataset('audiofolder', data_dir=f'./opus/{subset}', split='train')
|
28 |
+
datasets.append(dataset)
|
29 |
+
|
30 |
+
if len(datasets) > 1:
|
31 |
+
dataset = concatenate_datasets(datasets)
|
32 |
+
else:
|
33 |
+
dataset = datasets[0]
|
34 |
|
35 |
# List to store individual audio durations
|
36 |
durations = []
|
37 |
total_duration = 0
|
38 |
|
39 |
+
for item in tqdm(dataset):
|
40 |
file_path = item['audio']['path']
|
41 |
duration = get_audio_length(file_path)
|
42 |
durations.append(duration)
|
|
|
49 |
median_duration = np.median(durations)
|
50 |
|
51 |
# Print results
|
52 |
+
print(f"Statistics for: {' & '.join(subsets)}")
|
53 |
print(f"Total audio duration: {total_duration / 3600:.2f} hours")
|
54 |
print(f"Total audio duration: {total_duration / 60:.2f} minutes")
|
55 |
print(f"Minimum audio duration: {min_duration:.3f} seconds")
|
|
|
57 |
print(f"Average audio duration: {avg_duration:.3f} seconds")
|
58 |
print(f"Median audio duration: {median_duration:.3f} seconds")
|
59 |
|
60 |
+
# Concatenate metadata DataFrames
|
61 |
+
metadata_list = []
|
62 |
+
for subset in subsets:
|
63 |
+
metadata = read_csv(f'./opus/{subset}/metadata.csv')
|
64 |
+
metadata_list.append(metadata)
|
65 |
+
|
66 |
+
if len(metadata_list) > 1:
|
67 |
+
metadata = concat(metadata_list)
|
68 |
+
else:
|
69 |
+
metadata = metadata_list[0]
|
70 |
|
71 |
# Calculate total number of characters
|
72 |
total_characters = metadata['transcription'].str.len().sum()
|
|
|
87 |
print(f"Number of unique characters: {len(unique_characters)}")
|
88 |
print(f"Unique characters: {''.join(sorted(unique_characters))}")
|
89 |
print(f"Average speech rate: {total_characters / total_duration:.2f} characters per second")
|
90 |
+
print("-" * 20)
|
91 |
|
92 |
|
93 |
if __name__ == '__main__':
|
94 |
+
get_info('saamgwokjinji')
|
95 |
get_info('seoiwuzyun')
|
96 |
+
get_info(['saamgwokjinji', 'seoiwuzyun'])
|