Download DataAnalysisWithHistogram.py from awajai/IMEDATASET: direct link, hf CLI and curl.
- Browser
- Download file 109 kB
-
https://huggingface.co/datasets/awajai/IMEDATASET/resolve/main/DataAnalysisWithHistogram.py
- Command line
-
hf download hf://datasets/awajai/IMEDATASET/DataAnalysisWithHistogram.py
-
curl -L -o DataAnalysisWithHistogram.py https://huggingface.co/datasets/awajai/IMEDATASET/resolve/main/DataAnalysisWithHistogram.py
109 kB
| from datasets import load_dataset | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| data = load_dataset("rikeshsilwalekg/imeaudio", revision = "v3-output-audio-features", split="train") | |
| duration_values = [example['audio_features']['duration'] for example in data] | |
| ###########----------------__FOR DURATION__--------------------------------------######################## | |
| # Define bin width and bins for 0.5 seconds interval between 0 and 5 seconds | |
| bin_width = 0.5 | |
| min_duration = 25 | |
| max_duration = 30 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Filter data to only include durations between 0 and 5 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histtogram_25_30_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (25-30 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations0-5.jpg") | |
| plt.show() | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| # Define bin width and bins for 0.5 seconds interval between 0 and 5 seconds | |
| bin_width = 0.5 | |
| min_duration = 0 | |
| max_duration = 5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Filter data to only include durations between 0 and 5 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histtogram_0_51_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (0-5 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations0-5.jpg") | |
| plt.show() | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| # Define bin width and bins for 0.5 seconds interval between 5 and 10 seconds | |
| bin_width = 0.5 | |
| min_duration = 5 | |
| max_duration = 10 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Ensure duration_values is a NumPy array | |
| duration_values = np.array(duration_values) | |
| # Filter data to only include durations between 5 and 10 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histogram_5_10_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (5-10 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations5-10.jpg") | |
| plt.show() | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| # Define bin width and bins for 0.5 seconds interval between 5 and 10 seconds | |
| bin_width = 0.5 | |
| min_duration = 10 | |
| max_duration = 15 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Ensure duration_values is a NumPy array | |
| duration_values = np.array(duration_values) | |
| # Filter data to only include durations between 5 and 10 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histogram_10_15_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (10-15seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations10-15.jpg") | |
| plt.show() | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| # Example duration_values data (replace with your actual data) | |
| # duration_values = ... | |
| # Define bin width and bins for 0.5 seconds interval between 5 and 10 seconds | |
| bin_width = 0.5 | |
| min_duration = 15 | |
| max_duration = 20 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Ensure duration_values is a NumPy array | |
| duration_values = np.array(duration_values) | |
| # Filter data to only include durations between 10 and 15 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histogram_15_20_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (15-20 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations15-20.jpg") | |
| plt.show() | |
| import numpy as np | |
| import json | |
| import matplotlib.pyplot as plt | |
| # Example duration_values data (replace with your actual data) | |
| # duration_values = ... | |
| # Define bin width and bins for 0.5 seconds interval between 5 and 10 seconds | |
| bin_width = 0.5 | |
| min_duration = 20 | |
| max_duration = 25 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Ensure duration_values is a NumPy array | |
| duration_values = np.array(duration_values) | |
| # Filter data to only include durations between 10 and 15 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histogram_20_25_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (20-25 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AudioDurations20-25.jpg") | |
| plt.show() | |
| # Define bin width and bins for 0.5 seconds interval between 5 and 10 seconds | |
| bin_width = 0.5 | |
| min_duration = 25 | |
| max_duration = 30 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Ensure duration_values is a NumPy array | |
| duration_values = np.array(duration_values) | |
| # Filter data to only include durations between 10 and 15 seconds | |
| filtered_durations = duration_values[(duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram data | |
| counts, bin_edges = np.histogram(filtered_durations, bins=bins) | |
| # Prepare dictionary with string keys for each bin range | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save histogram data to JSON file | |
| json_filename = "audio_duration_histogram_25-30_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_durations, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Audio Durations (20-25 seconds)') | |
| plt.xlabel('Duration in seconds') | |
| plt.ylabel('Count') | |
| plt.xlim(min_duration, max_duration) | |
| # plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA0-5.jpg") | |
| plt.show() | |
| ###########-----------------------------------------__FOR DYNAMIC_RANGE_LRA__-------------------------------------------------------------------######################## | |
| dynamic_range_lra = [example['audio_features']['dynamic_range_lra'] for example in data] | |
| bin_width = 0.5 | |
| min_duration = 0 | |
| max_duration = 5 | |
| # Ensure arrays are numpy arrays | |
| duration_values = np.array(duration_values) | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter dynamic_range_lra for files with duration between 0 and 5 seconds | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration) | |
| ] | |
| # Define bins for dynamic_range_lra (0 to 30 in 0.5 steps) | |
| lra_bins = np.arange(0, 5 + bin_width, bin_width) | |
| # Compute histogram for filtered dynamic_range_lra | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=lra_bins) | |
| # Prepare JSON output in requested format | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON | |
| json_filename = "dynamic_range_lra_histogram_0_5_seconds.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot | |
| plt.hist(filtered_dynamic_range_lra, bins=lra_bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (0-5 seconds duration)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(0, 5) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA0-5.jpg") | |
| plt.show() | |
| # Define bin width and range for dynamic range LRA between 5-10 | |
| bin_width = 0.5 | |
| min_lra = 5 | |
| max_lra = 10 | |
| bins = np.arange(min_lra, max_lra + bin_width, bin_width) | |
| # Ensure data is in numpy arrays | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter to only include dynamic range LRA values between 5-10 | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram for the filtered values | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=bins) | |
| # Prepare JSON with string keys | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON file | |
| json_filename = "dynamic_range_lra_histogram_5_10.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_dynamic_range_lra, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (5-10)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(min_lra, max_lra) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA5-10.jpg") | |
| plt.show() | |
| # Define bin width and range for dynamic range LRA between 10-15 | |
| bin_width = 0.5 | |
| min_lra = 10 | |
| max_lra = 15 | |
| bins = np.arange(min_lra, max_lra + bin_width, bin_width) | |
| # Ensure data is in numpy arrays | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter to only include dynamic range LRA values between 10-15 | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram for the filtered values | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=bins) | |
| # Prepare JSON with string keys | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON file | |
| json_filename = "dynamic_range_lra_histogram_10_15.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_dynamic_range_lra, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (10-15)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(min_lra, max_lra) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA10-15.jpg") | |
| plt.show() | |
| # Define bin width and range for dynamic range LRA between 10-15 | |
| bin_width = 0.5 | |
| min_lra = 15 | |
| max_lra = 20 | |
| bins = np.arange(min_lra, max_lra + bin_width, bin_width) | |
| # Ensure data is in numpy arrays | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter to only include dynamic range LRA values between 10-15 | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram for the filtered values | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=bins) | |
| # Prepare JSON with string keys | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON file | |
| json_filename = "dynamic_range_lra_histogram_15_20.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_dynamic_range_lra, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (15-20)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(min_lra, max_lra) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA15-20.jpg") | |
| plt.show() | |
| # Define bin width and range for dynamic range LRA between 10-15 | |
| bin_width = 0.5 | |
| min_lra = 20 | |
| max_lra = 25 | |
| bins = np.arange(min_lra, max_lra + bin_width, bin_width) | |
| # Ensure data is in numpy arrays | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter to only include dynamic range LRA values between 10-15 | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram for the filtered values | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=bins) | |
| # Prepare JSON with string keys | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON file | |
| json_filename = "dynamic_range_lra_histogram_20_25.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_dynamic_range_lra, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (20-25)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(min_lra, max_lra) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA20-25.jpg") | |
| plt.show() | |
| # Define bin width and range for dynamic range LRA between 10-15 | |
| bin_width = 0.5 | |
| min_lra = 25 | |
| max_lra = 30 | |
| bins = np.arange(min_lra, max_lra + bin_width, bin_width) | |
| # Ensure data is in numpy arrays | |
| dynamic_range_lra_values = np.array(dynamic_range_lra) | |
| # Filter to only include dynamic range LRA values between 10-15 | |
| filtered_dynamic_range_lra = dynamic_range_lra_values[ | |
| (duration_values >= min_duration) & (duration_values <= max_duration)] | |
| # Compute histogram for the filtered values | |
| counts, bin_edges = np.histogram(filtered_dynamic_range_lra, bins=bins) | |
| # Prepare JSON with string keys | |
| hist_dict = {} | |
| for i in range(len(counts)): | |
| key = f"{bin_edges[i]}-{bin_edges[i+1]}" | |
| hist_dict[key] = int(counts[i]) | |
| # Save to JSON file | |
| json_filename = "dynamic_range_lra_histogram_25-30.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(hist_dict, f, indent=2) | |
| # Plot histogram | |
| plt.hist(filtered_dynamic_range_lra, bins=bins, color='purple', edgecolor='black') | |
| plt.title('Distribution of Dynamic Range LRA (25-30)') | |
| plt.xlabel('Dynamic Range LRA') | |
| plt.ylabel('Count') | |
| plt.xlim(min_lra, max_lra) | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration//DynamicRangeLRA25-30.jpg") | |
| plt.show() | |
| ##################-------------------------------------FOR LOUDNESS LUFFS----------------------------------------------------------------------#################### | |
| loudness_lufs = [example['audio_features']['loudness_lufs'] for example in data] | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 0 | |
| max_duration = 5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNsplt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/Dynamic-Range-LRA0-5.jpg") | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (0–5 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness0-5.jpg") | |
| plt.show() | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 5 | |
| max_duration = 10 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNs | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration5-10_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (5-10 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness5-10.jpg") | |
| plt.show() | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 10 | |
| max_duration = 15 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNs | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration10-15_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (10-15 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness10-15.jpg") | |
| plt.show() | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 15 | |
| max_duration = 20 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNs | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration15-20_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (15-20sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness15-20.jpg") | |
| plt.show() | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 20 | |
| max_duration = 25 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNs | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration20-25_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (20-25sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness20-25.jpg") | |
| plt.show() | |
| # Convert to numpy arrays | |
| duration_array = np.array(duration_values) | |
| loudness_array = np.array(loudness_lufs) | |
| # Define duration bins (0 to 5 seconds, 0.5s intervals) | |
| bin_width = 0.5 | |
| min_duration = 25 | |
| max_duration = 30 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| loudness_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through bins and compute average loudness | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask for samples in the duration bin | |
| mask = (duration_array >= start) & (duration_array < end) | |
| loudness_in_bin = loudness_array[mask] | |
| # Remove NaNs | |
| loudness_in_bin = loudness_in_bin[~np.isnan(loudness_in_bin)] | |
| # Calculate mean loudness | |
| if len(loudness_in_bin) > 0: | |
| avg_loudness = float(np.mean(loudness_in_bin)) | |
| else: | |
| avg_loudness = None | |
| # Save results | |
| key = f"{start}-{end}" | |
| loudness_per_duration_bin[key] = avg_loudness | |
| x_labels.append(key) | |
| y_values.append(avg_loudness if avg_loudness is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_loudness_lufs_per_duration25-30_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(loudness_per_duration_bin, f, indent=2) | |
| # Plot histogram-style bar chart | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Loudness (LUFS)") | |
| plt.title("Average Loudness per Duration Bin (25-30sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/loudness25-30.jpg") | |
| plt.show() | |
| ##########-------------------------AVERAGE MEAN f0--------------------------------------------__############################################# | |
| mean_f0_hz = [example['audio_features']['mean_f0_hz'] for example in data] | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 0 | |
| max_duration = 5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration0-5_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (0–5 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:0-5.jpg") | |
| plt.show() | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 5 | |
| max_duration = 10 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration5-10_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (5-10 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:5-10.jpg") | |
| plt.show() | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 10 | |
| max_duration = 15 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration10-15_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (10-15 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:10-15.jpg") | |
| plt.show() | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 15 | |
| max_duration = 20 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration_bin15-20.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (15-20 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:15-20.jpg") | |
| plt.show() | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 20 | |
| max_duration = 25 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration20-25_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (20-25 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:20-25.jpg") | |
| plt.show() | |
| # Clean your data: convert to float or np.nan | |
| cleaned_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in mean_f0_hz] | |
| f0_array = np.array(cleaned_f0, dtype=np.float32) | |
| # Also clean durations to match | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins | |
| bin_width = 0.5 | |
| min_duration = 25 | |
| max_duration = 30 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Prepare results | |
| f0_per_duration_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| # Loop through each bin | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Mask valid values only | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(f0_array) | |
| f0_in_bin = f0_array[mask] | |
| avg_f0 = float(np.mean(f0_in_bin)) if len(f0_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| f0_per_duration_bin[key] = avg_f0 | |
| x_labels.append(key) | |
| y_values.append(avg_f0 if avg_f0 is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_f0_hz_per_duration25-30_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(f0_per_duration_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='salmon', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Mean F0 (Hz)") | |
| plt.title("Average Mean F0 per Duration Bin (25-30 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgMeanF0:25-30.jpg") | |
| plt.show() | |
| ########################--------------------------------__MEAN SPECTRAL_CENTROID--------------------------------------------------------____#########################3 | |
| mean_spectral_centroid_hz = [example['audio_features']['mean_spectral_centroid_hz'] for example in data] | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 0 | |
| max_duration = 5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entries | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration0-5_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (0–5 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral0-5.jpg") | |
| plt.show() | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 5 | |
| max_duration = 10 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entries | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration5-10_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (5-10 sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral5-10.jpg") | |
| plt.show() | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 10 | |
| max_duration = 15 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entrieplt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral0-5.jpg")s | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration10-15_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (10-15) sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral10-15.jpg") | |
| plt.show() | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 15 | |
| max_duration = 20 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entries | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration15-20_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (15-20) sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral15-20.jpg") | |
| plt.show() | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 20 | |
| max_duration = 25 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entries | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration20-25_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (20-25) sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral20-25.jpg") | |
| plt.show() | |
| # Clean spectral centroid values | |
| cleaned_centroid = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in mean_spectral_centroid_hz | |
| ] | |
| centroid_array = np.array(cleaned_centroid, dtype=np.float32) | |
| # Clean duration values | |
| cleaned_durations = [ | |
| float(x) if isinstance(x, (int, float)) and x is not None else np.nan | |
| for x in duration_values | |
| ] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| # Define duration bins (0–5s with 0.5s step) | |
| bin_width = 0.5 | |
| min_duration = 25 | |
| max_duration = 30 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Compute average per bin | |
| centroid_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| start = bins[i] | |
| end = bins[i + 1] | |
| # Filter valid entries | |
| mask = (duration_array >= start) & (duration_array < end) & ~np.isnan(centroid_array) | |
| values_in_bin = centroid_array[mask] | |
| avg_centroid = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| centroid_per_bin[key] = avg_centroid | |
| x_labels.append(key) | |
| y_values.append(avg_centroid if avg_centroid is not None else 0) | |
| # Save to JSON | |
| json_filename = "avg_mean_spectral_centroid_hz_per_duration25-30_bin.json" | |
| with open(json_filename, "w") as f: | |
| json.dump(centroid_per_bin, f, indent=2) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='royalblue', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (seconds)") | |
| plt.ylabel("Average Spectral Centroid (Hz)") | |
| plt.title("Average Spectral Centroid per Duration Bin (20-25) sec)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpectral25-30jpg") | |
| plt.show() | |
| ###--------------------------------------------------SNR ESTIMATE DB----------------------------------------------------------####### | |
| snr_estimate_db= [example['audio_features']['snr_estimate_db'] for example in data] | |
| min_duration = 0 | |
| max_duration = 5 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration0-5_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR0-5.jpg") | |
| plt.show() | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration5-10_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR5-10.jpg") | |
| plt.show() | |
| min_duration = 10 | |
| max_duration = 15 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration10-15_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR10-15.jpg") | |
| plt.show() | |
| min_duration = 15 | |
| max_duration = 20 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration15-20_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR15-20.jpg") | |
| plt.show() | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration20-25_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR20-25.jpg") | |
| plt.show() | |
| min_duration = 25 | |
| max_duration = 30 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_snr = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in snr_estimate_db] | |
| snr_array = np.array(cleaned_snr, dtype=np.float32) | |
| cleaned_durations = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in duration_values] | |
| duration_array = np.array(cleaned_durations, dtype=np.float32) | |
| snr_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(snr_array) | |
| values = snr_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| snr_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_snr_estimate_db_per_duration25-30_bin.json", "w") as f: | |
| json.dump(snr_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='teal', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg SNR (dB)") | |
| plt.title("Average SNR Estimate per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSNR25-30jpg") | |
| plt.show() | |
| #############-----------------------------------------------------SPEECH PERCENTAGE------------------------------------------------------_#################### | |
| speech_percentage= [example['audio_features']['speech_percentage'] for example in data] | |
| min_duration = 0 | |
| max_duration = 5 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration0-5_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/avg_speech/AverageSpeechPercentage0-5.jpg") | |
| plt.show() | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration5-10_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpeechPercentage5-10.jpg") | |
| plt.show() | |
| min_duration = 10 | |
| max_duration = 15 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration10-15_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpeechPercentage10-15.jpg") | |
| plt.show() | |
| min_duration = 15 | |
| max_duration = 20 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration15-20_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpeechPercentage15-20.jpg") | |
| plt.show() | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration20-25_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpeechPercentage20-25.jpg") | |
| plt.show() | |
| min_duration = 25 | |
| max_duration = 30 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_speech_pct = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in speech_percentage] | |
| speech_pct_array = np.array(cleaned_speech_pct, dtype=np.float32) | |
| speech_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(speech_pct_array) | |
| values = speech_pct_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speech_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_speech_percentage_per_duration25-30_bin.json", "w") as f: | |
| json.dump(speech_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='green', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Speech %") | |
| plt.title("Average Speech Percentage per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AverageSpeechPercentage25-30.jpg") | |
| plt.show() | |
| #########################------------------_______AVG_STD_DEV_F0--------------------------------------------------___________############################ | |
| std_dev_f0_hz = [example['audio_features']['std_dev_f0_hz'] for example in data] | |
| min_duration = 0 | |
| max_duration = 5 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration0-5_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev0-5.jpg") | |
| plt.show() | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration5-10_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev5-10.jpg") | |
| plt.show() | |
| min_duration = 10 | |
| max_duration = 15 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration10-15_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev10-15.jpg") | |
| plt.show() | |
| min_duration = 15 | |
| max_duration = 20 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration15-20_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev15-20.jpg") | |
| plt.show() | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration20-25_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev20-25.jpg") | |
| plt.show() | |
| min_duration = 25 | |
| max_duration = 30 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| cleaned_std_f0 = [float(x) if isinstance(x, (int, float)) and x is not None else np.nan for x in std_dev_f0_hz] | |
| std_f0_array = np.array(cleaned_std_f0, dtype=np.float32) | |
| std_f0_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) & ~np.isnan(std_f0_array) | |
| values = std_f0_array[mask] | |
| avg = float(np.mean(values)) if len(values) > 0 else None | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| std_f0_per_bin[key] = avg | |
| x_labels.append(key) | |
| y_values.append(avg if avg is not None else 0) | |
| with open("avg_std_dev_f0_hz_per_duration25-30_bin.json", "w") as f: | |
| json.dump(std_f0_per_bin, f, indent=2) | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='violet', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Avg Std Dev F0 (Hz)") | |
| plt.title("Avg Std Dev of F0 per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/AvgStdDev25-30.jpg") | |
| plt.show() | |
| ###############################3-------------------------------------_BANDWIDTH CATEGORY--------------------------------------------------------------####### | |
| bandwidth_category = [example['audio_features']['bandwidth_category'] for example in data] | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 0 | |
| max_duration = 5 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration0-5_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration5_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration5-10_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration10-15_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration10-15_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 15 | |
| max_duration = 20 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration15-20_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration15-20_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration20-25_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration20-25_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration20-25_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/bandwidth_duration20-25_histogram.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 25 | |
| max_duration = 30 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert lists to arrays | |
| bandwidth_category_array = np.array(bandwidth_category, dtype=object) | |
| duration_array = np.array(duration_values, dtype=np.float32) | |
| # Create result dict | |
| bandwidth_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| # Mask: duration in bin and bandwidth_category is valid | |
| mask = ( | |
| (duration_array >= start) & | |
| (duration_array < end) & | |
| np.array([x is not None and x != '' for x in bandwidth_category_array]) | |
| ) | |
| # Filter categories | |
| categories_in_bin = bandwidth_category_array[mask] | |
| # Count occurrences of each category | |
| category_counts = {} | |
| for category in categories_in_bin: | |
| category_counts[category] = category_counts.get(category, 0) + 1 | |
| # Save to dict | |
| key = f"{start}-{end}" | |
| bandwidth_per_bin[key] = category_counts | |
| x_labels.append(key) | |
| # Save result as JSON | |
| with open("bandwidth_category_per_duration25-30_bin.json", "w") as f: | |
| json.dump(bandwidth_per_bin, f, indent=2) | |
| # Prepare data for plotting | |
| category_labels = list(set(cat for bin_data in bandwidth_per_bin.values() for cat in bin_data.keys())) | |
| category_counts = {category: [] for category in category_labels} | |
| for label in x_labels: | |
| bin_data = bandwidth_per_bin[label] | |
| for category in category_labels: | |
| category_counts[category].append(bin_data.get(category, 0)) | |
| # Plot | |
| plt.figure(figsize=(10, 6)) | |
| bar_width = 0.1 | |
| for idx, category in enumerate(category_labels): | |
| plt.bar( | |
| np.arange(len(x_labels)) + idx * bar_width, | |
| category_counts[category], | |
| width=bar_width, | |
| label=category | |
| ) | |
| plt.xticks(np.arange(len(x_labels)) + bar_width * (len(category_labels) - 1) / 2, x_labels, rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Bandwidth Category per Duration Bin") | |
| plt.legend(title="Bandwidth Category") | |
| plt.tight_layout() | |
| # plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/bandwidth_category/audio_duration_histogram0-5.jpg") | |
| plt.show() | |
| ##########--------------------------CLIPPING PERCENTAGE----------------------------------________############################ | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Extract data | |
| clipping_percentage = [example['audio_features']['clipping_percentage'] for example in data] | |
| duration_values = [example['audio_features']['duration'] for example in data] | |
| # Define duration bin range | |
| min_duration = 0 | |
| max_duration = 5 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration0-5_bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram0-5.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 5 | |
| max_duration = 10 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration5-10_bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram5-10.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 10 | |
| max_duration = 15 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration10-15_bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram10-15.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 15 | |
| max_duration = 20 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration15-20_bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram15-20.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 20 | |
| max_duration = 25 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration20-25_bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram20-25.jpg") | |
| plt.show() | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Define duration bin range | |
| min_duration = 25 | |
| max_duration = 30 | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Convert to numpy arrays | |
| clipping_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in clipping_percentage | |
| ], dtype=np.float32) | |
| duration_array = np.array([ | |
| float(x) if isinstance(x, (float, int)) and x is not None else np.nan | |
| for x in duration_values | |
| ], dtype=np.float32) | |
| # Compute average clipping_percentage per duration bin | |
| clipping_per_bin = {} | |
| x_labels = [] | |
| for i in range(len(bins) - 1): | |
| start, end = bins[i], bins[i + 1] | |
| mask = (duration_array >= start) & (duration_array < end) | |
| values_in_bin = clipping_array[mask] | |
| values_in_bin = values_in_bin[~np.isnan(values_in_bin)] | |
| avg_clip = float(np.mean(values_in_bin)) if len(values_in_bin) > 0 else None | |
| key = f"{start}-{end}" | |
| clipping_per_bin[key] = avg_clip | |
| x_labels.append(key) | |
| # Save JSON | |
| with open("clipping_percentage_per_duration25-30bin.json", "w") as f: | |
| json.dump(clipping_per_bin, f, indent=2) | |
| # Plot | |
| heights = [clipping_per_bin[label] if clipping_per_bin[label] is not None else 0 for label in x_labels] | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, heights, color='teal', edgecolor='black') | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Average Clipping Percentage") | |
| plt.title("Average Clipping Percentage per Duration Bin") | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/Avg_clipping_percentage/clipping_Percent_histogram25-30.jpg") | |
| plt.show() | |
| ########################_-----------------------------------__SPEAKER COUNT--------------------------------___############################33 | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| # Work with the Dataset object format | |
| # Your data is already loaded in a variable called 'data' | |
| # Extract duration and speaker count from the dataset | |
| durations = [] | |
| speaker_counts = [] | |
| # Process each item in the dataset | |
| # For HuggingFace/datasets library | |
| try: | |
| # This should work for most Dataset objects | |
| audio_features = data['audio_features'] | |
| # If audio_features is directly accessible | |
| if isinstance(audio_features, list): | |
| for features in audio_features: | |
| if features is not None: | |
| duration = features.get('duration') | |
| speaker_count = features.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| else: | |
| # If we need to iterate through the dataset | |
| for i in range(len(data)): | |
| features = data[i]['audio_features'] | |
| if features is not None: | |
| duration = features.get('duration') | |
| speaker_count = features.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| except Exception as e: | |
| print(f"Error accessing dataset: {e}") | |
| # Alternative approach if the above doesn't work | |
| print("Trying alternative approach...") | |
| # If data is a list of dictionaries | |
| if isinstance(data, list): | |
| for item in data: | |
| if isinstance(item, dict) and 'duration' in item and 'speaker_count' in item: | |
| duration = item.get('duration') | |
| speaker_count = item.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| # Convert to numpy arrays | |
| duration_array = np.array(durations) | |
| speaker_count_array = np.array(speaker_counts) | |
| # Print data summary | |
| print(f"Duration array shape: {duration_array.shape}") | |
| print(f"Speaker count array shape: {speaker_count_array.shape}") | |
| if len(durations) > 0: | |
| print(f"Duration range: {np.min(duration_array):.2f} to {np.max(duration_array):.2f} seconds") | |
| print(f"Speaker count range: {np.min(speaker_count_array)} to {np.max(speaker_count_array)} speakers") | |
| else: | |
| print("No valid data extracted!") | |
| # Based on your sample, the durations are quite short (around 2-3 seconds) | |
| # Adjust min_duration and max_duration to match your actual data | |
| min_duration = 0 | |
| max_duration = 5 # Increased range to capture more data | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Count speakers per bin | |
| speaker_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) | |
| # Count the number of samples in this bin | |
| count = np.sum(mask) | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speaker_per_bin[key] = int(count) | |
| x_labels.append(key) | |
| y_values.append(count) | |
| # Print counts for debugging | |
| print(f"Bin {key}: {count} audio files") | |
| # Save to JSON | |
| with open("speaker_count_per_duration_bin0-5.json", "w") as f: | |
| json.dump(speaker_per_bin, f, indent=2) | |
| # Plot the results | |
| if sum(y_values) > 0: | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(x_labels, y_values, color='orange', edgecolor='black') | |
| plt.xticks(rotation=45) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title("Number of Audio Files per Duration Bin") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| plt.savefig("/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration/SpeakerCountPerDurationBin0-5.jpg") | |
| plt.show() | |
| else: | |
| print("No data found in the specified duration range! Try adjusting your min_duration and max_duration.") | |
| # If no data in specified range, show the actual duration distribution | |
| print("\nAnalyzing your actual data distribution...") | |
| actual_min = np.min(duration_array) | |
| actual_max = np.max(duration_array) | |
| print(f"Your data ranges from {actual_min:.2f} to {actual_max:.2f} seconds") | |
| # Suggest a better range based on actual data | |
| hist, bin_edges = np.histogram(duration_array, bins=10) | |
| print("Top duration ranges in your data:") | |
| for i in range(len(hist)): | |
| if hist[i] > 0: | |
| print(f"{bin_edges[i]:.2f}-{bin_edges[i+1]:.2f} seconds: {hist[i]} samples") | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import json | |
| import os | |
| # Create output directory if it doesn't exist | |
| output_dir = "/home/sidd/Desktop/work/IME DATASET REVIEW/audio_duration" | |
| os.makedirs(output_dir, exist_ok=True) | |
| # Define duration ranges to analyze | |
| duration_ranges = [ | |
| (5, 10), | |
| (10, 15), | |
| (15, 20), | |
| (20, 25), | |
| (25, 30) | |
| ] | |
| # Extract duration and speaker count from the dataset | |
| durations = [] | |
| speaker_counts = [] | |
| # Process each item in the dataset | |
| try: | |
| # For HuggingFace datasets | |
| audio_features = data['audio_features'] | |
| if isinstance(audio_features, list): | |
| for features in audio_features: | |
| if features is not None: | |
| duration = features.get('duration') | |
| speaker_count = features.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| else: | |
| # If we need to iterate through the dataset | |
| for i in range(len(data)): | |
| features = data[i]['audio_features'] | |
| if features is not None: | |
| duration = features.get('duration') | |
| speaker_count = features.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| except Exception as e: | |
| print(f"Error accessing dataset: {e}") | |
| # Alternative approach if the above doesn't work | |
| print("Trying alternative approach...") | |
| # If data is a list of dictionaries | |
| if isinstance(data, list): | |
| for item in data: | |
| if isinstance(item, dict) and 'duration' in item and 'speaker_count' in item: | |
| duration = item.get('duration') | |
| speaker_count = item.get('speaker_count') | |
| if duration is not None and speaker_count is not None: | |
| durations.append(duration) | |
| speaker_counts.append(speaker_count) | |
| # Convert to numpy arrays | |
| duration_array = np.array(durations) | |
| speaker_count_array = np.array(speaker_counts) | |
| # Print overall data summary | |
| print(f"Total data points extracted: {len(durations)}") | |
| if len(durations) > 0: | |
| print(f"Overall duration range: {np.min(duration_array):.2f} to {np.max(duration_array):.2f} seconds") | |
| print(f"Overall speaker count range: {np.min(speaker_count_array)} to {np.max(speaker_count_array)} speakers") | |
| else: | |
| print("No valid data extracted!") | |
| exit() | |
| # Process each duration range | |
| for min_duration, max_duration in duration_ranges: | |
| print(f"\nProcessing duration range {min_duration}-{max_duration} seconds...") | |
| # Filter data for this range | |
| range_mask = (duration_array >= min_duration) & (duration_array < max_duration) | |
| range_count = np.sum(range_mask) | |
| print(f"Found {range_count} audio files in this range") | |
| # If no data in this range, skip to the next | |
| if range_count == 0: | |
| print(f"No data in the {min_duration}-{max_duration} second range, skipping...") | |
| continue | |
| # Define bins for this range | |
| bin_width = 0.5 | |
| bins = np.arange(min_duration, max_duration + bin_width, bin_width) | |
| # Count speakers per bin | |
| speaker_per_bin = {} | |
| x_labels = [] | |
| y_values = [] | |
| for i in range(len(bins) - 1): | |
| mask = (duration_array >= bins[i]) & (duration_array < bins[i+1]) | |
| # Count the number of samples in this bin | |
| count = np.sum(mask) | |
| key = f"{bins[i]}-{bins[i+1]}" | |
| speaker_per_bin[key] = int(count) | |
| x_labels.append(key) | |
| y_values.append(count) | |
| # Print counts for debugging | |
| print(f"Bin {key}: {count} audio files") | |
| # Save to JSON for this range | |
| json_filename = f"speaker_count_per_duration_bin{min_duration}-{max_duration}.json" | |
| json_path = os.path.join(output_dir, json_filename) | |
| with open(json_path, "w") as f: | |
| json.dump(speaker_per_bin, f, indent=2) | |
| print(f"Saved results to {json_path}") | |
| # Plot the results for this range | |
| plt.figure(figsize=(12, 6)) | |
| plt.bar(x_labels, y_values, color='orange', edgecolor='black') | |
| plt.xticks(rotation=90) | |
| plt.xlabel("Duration Bin (s)") | |
| plt.ylabel("Count") | |
| plt.title(f"Number of Audio Files per Duration Bin ({min_duration}-{max_duration}s)") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| # Save the plot for this range | |
| plot_filename = f"SpeakerCountPerDurationBin{min_duration}-{max_duration}.jpg" | |
| plot_path = os.path.join(output_dir, plot_filename) | |
| plt.savefig(plot_path) | |
| print(f"Saved plot to {plot_path}") | |
| plt.close() | |
| print("\nAll duration ranges processed!") | |
| # Create a combined plot showing summary for all ranges | |
| range_counts = [] | |
| range_labels = [] | |
| for min_duration, max_duration in duration_ranges: | |
| range_mask = (duration_array >= min_duration) & (duration_array < max_duration) | |
| range_count = np.sum(range_mask) | |
| range_counts.append(range_count) | |
| range_labels.append(f"{min_duration}-{max_duration}s") | |
| # Plot the summary | |
| plt.figure(figsize=(10, 6)) | |
| plt.bar(range_labels, range_counts, color='blue', edgecolor='black') | |
| plt.xlabel("Duration Range (seconds)") | |
| plt.ylabel("Number of Audio Files") | |
| plt.title("Distribution of Audio Files Across Duration Ranges") | |
| plt.grid(axis='y') | |
| plt.tight_layout() | |
| # Save the summary plot | |
| summary_path = os.path.join(output_dir, "DurationRangeSummary.jpg") | |
| plt.savefig(summary_path) | |
| print(f"Saved summary plot to {summary_path}") | |
| plt.close() | |
| print("All processing completed successfully!") | |