RaivisDejus commited on
Commit
b30c3db
·
verified ·
1 Parent(s): c60050d

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc0-1.0
3
+ language:
4
+ - lv
5
+ pipeline_tag: text-to-speech
6
+ ---
7
+ # Latvian TTS dataset "Rūdolfs"
8
+
9
+ Dataset is created from [audio books](https://www.youtube.com/@LatvijasNeredzigobiblioteka) of
10
+ [Latvijas Neredzīgo bibliotēka](https://neredzigobiblioteka.lv/). For permission reasons the original voice
11
+ in the recordings has been cloned to a donor voice.
12
+ Audio book recordings are used with permission from Latvijas Neredzīgo bibliotēka.
13
+
14
+ ## Optional processing
15
+
16
+ For some tastes the "s" sounds in the clips released may feel too harsh.
17
+ To reduce them use the `sibilant_reducer.py` script.
18
+
19
+ ```commandline
20
+ uv run python sibilant_reducer.py --input-dir ../clips/wav --output-dir ../clips/wav_deessed
21
+ ```
clips/metadata.csv ADDED
The diff for this file is too large to render. See raw diff
 
clips/wav.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daab56577f0f2295633635c03d185bddaf61d4531214a3d56de9e89f0bb1402d
3
+ size 13830896049
sibilant-reducer/pyproject.toml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "sibilant-reducer"
3
+ version = "0.1.0"
4
+ description = "Automatically detects and shortens excessively long sibilant sounds in audio"
5
+ requires-python = ">=3.10"
6
+ dependencies = [
7
+ "numpy",
8
+ "scipy",
9
+ "soundfile",
10
+ "tqdm",
11
+ ]
sibilant-reducer/sibilant_reducer.py ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Sibilant Duration Reducer
4
+
5
+ Automatically detects and shortens excessively long sibilant ("SSS") sounds
6
+ in audio recordings by cutting out the middle portion and crossfading.
7
+ """
8
+
9
+ import argparse
10
+ from pathlib import Path
11
+
12
+ import numpy as np
13
+ import soundfile as sf
14
+ from scipy.signal import stft
15
+ from tqdm import tqdm
16
+
17
+ # Default parameters
18
+ SIBILANT_FREQ_LOW = 4000 # Hz
19
+ SIBILANT_FREQ_HIGH = 10000 # Hz
20
+ MAX_SIBILANT_DURATION = 0.070 # seconds (70ms)
21
+ CROSSFADE_DURATION = 0.010 # seconds (10ms)
22
+ DETECTION_THRESHOLD = 0.1 # relative energy threshold
23
+ MIN_GAP_DURATION = 0.020 # seconds - gaps smaller than this merge regions
24
+
25
+
26
+ def detect_sibilants(
27
+ samples: np.ndarray,
28
+ sr: int,
29
+ freq_low: float,
30
+ freq_high: float,
31
+ threshold: float,
32
+ min_gap: float,
33
+ ) -> list[tuple[int, int]]:
34
+ """
35
+ Detect sibilant regions in audio by analyzing high-frequency energy.
36
+
37
+ Returns list of (start_sample, end_sample) tuples for detected sibilants.
38
+ """
39
+ # STFT parameters
40
+ nperseg = 512
41
+ noverlap = nperseg // 2
42
+ hop = nperseg - noverlap
43
+
44
+ # Compute STFT
45
+ freqs, times, Zxx = stft(samples, fs=sr, nperseg=nperseg, noverlap=noverlap)
46
+
47
+ # Find frequency bin indices for sibilant band
48
+ freq_mask = (freqs >= freq_low) & (freqs <= freq_high)
49
+
50
+ # Calculate energy in sibilant band for each frame
51
+ sibilant_energy = np.sum(np.abs(Zxx[freq_mask, :]) ** 2, axis=0)
52
+
53
+ # Normalize energy
54
+ if sibilant_energy.max() > 0:
55
+ sibilant_energy = sibilant_energy / sibilant_energy.max()
56
+ else:
57
+ return []
58
+
59
+ # Threshold to find sibilant frames
60
+ is_sibilant = sibilant_energy > threshold
61
+
62
+ # Convert frame indices to sample indices
63
+ frame_to_sample = lambda f: int(f * hop)
64
+
65
+ # Find contiguous regions
66
+ regions = []
67
+ in_region = False
68
+ start_frame = 0
69
+
70
+ for i, is_sib in enumerate(is_sibilant):
71
+ if is_sib and not in_region:
72
+ start_frame = i
73
+ in_region = True
74
+ elif not is_sib and in_region:
75
+ regions.append((frame_to_sample(start_frame), frame_to_sample(i)))
76
+ in_region = False
77
+
78
+ # Handle region extending to end
79
+ if in_region:
80
+ regions.append((frame_to_sample(start_frame), frame_to_sample(len(is_sibilant))))
81
+
82
+ # Merge regions with small gaps
83
+ min_gap_samples = int(min_gap * sr)
84
+ merged_regions = []
85
+
86
+ for start, end in regions:
87
+ if merged_regions and start - merged_regions[-1][1] < min_gap_samples:
88
+ # Merge with previous region
89
+ merged_regions[-1] = (merged_regions[-1][0], end)
90
+ else:
91
+ merged_regions.append((start, end))
92
+
93
+ # Clamp to valid sample range
94
+ merged_regions = [
95
+ (max(0, start), min(len(samples), end)) for start, end in merged_regions
96
+ ]
97
+
98
+ return merged_regions
99
+
100
+
101
+ def shorten_sibilant(
102
+ samples: np.ndarray,
103
+ start: int,
104
+ end: int,
105
+ sr: int,
106
+ max_duration: float,
107
+ crossfade_duration: float,
108
+ ) -> tuple[np.ndarray, int]:
109
+ """
110
+ Shorten a sibilant region by cutting out the middle and crossfading.
111
+
112
+ Returns (shortened_segment, samples_removed).
113
+ """
114
+ segment = samples[start:end]
115
+ segment_duration = len(segment) / sr
116
+
117
+ if segment_duration <= max_duration:
118
+ return segment, 0
119
+
120
+ # Calculate how many samples to keep
121
+ max_samples = int(max_duration * sr)
122
+ crossfade_samples = int(crossfade_duration * sr)
123
+
124
+ # Ensure we have enough samples for crossfade
125
+ if max_samples < 2 * crossfade_samples:
126
+ crossfade_samples = max_samples // 4
127
+
128
+ # Split: keep beginning and end, remove middle
129
+ keep_each_side = max_samples // 2
130
+
131
+ before = segment[:keep_each_side]
132
+ after = segment[-keep_each_side:]
133
+
134
+ # Apply crossfade at the junction
135
+ if crossfade_samples > 0 and len(before) >= crossfade_samples and len(after) >= crossfade_samples:
136
+ fade_out = np.linspace(1.0, 0.0, crossfade_samples)
137
+ fade_in = np.linspace(0.0, 1.0, crossfade_samples)
138
+
139
+ # Crossfade the overlapping portion
140
+ before_fade = before[-crossfade_samples:] * fade_out
141
+ after_fade = after[:crossfade_samples] * fade_in
142
+ crossfaded = before_fade + after_fade
143
+
144
+ # Construct shortened segment
145
+ shortened = np.concatenate([
146
+ before[:-crossfade_samples],
147
+ crossfaded,
148
+ after[crossfade_samples:]
149
+ ])
150
+ else:
151
+ # No crossfade possible, just concatenate
152
+ shortened = np.concatenate([before, after])
153
+
154
+ samples_removed = len(segment) - len(shortened)
155
+ return shortened, samples_removed
156
+
157
+
158
+ def process_audio(
159
+ samples: np.ndarray,
160
+ sr: int,
161
+ freq_low: float,
162
+ freq_high: float,
163
+ threshold: float,
164
+ max_duration: float,
165
+ crossfade_duration: float,
166
+ min_gap: float,
167
+ ) -> tuple[np.ndarray, int, int]:
168
+ """
169
+ Process audio to shorten long sibilants.
170
+
171
+ Returns (processed_samples, num_sibilants_shortened, total_samples_removed).
172
+ """
173
+ # Detect sibilants
174
+ regions = detect_sibilants(samples, sr, freq_low, freq_high, threshold, min_gap)
175
+
176
+ # Filter to only long sibilants
177
+ max_samples = int(max_duration * sr)
178
+ long_regions = [(s, e) for s, e in regions if (e - s) > max_samples]
179
+
180
+ if not long_regions:
181
+ return samples, 0, 0
182
+
183
+ # Process regions from end to start (to preserve indices)
184
+ result = samples.copy()
185
+ total_removed = 0
186
+
187
+ for start, end in reversed(long_regions):
188
+ shortened, removed = shorten_sibilant(
189
+ result, start, end, sr, max_duration, crossfade_duration
190
+ )
191
+ # Replace the region with shortened version
192
+ result = np.concatenate([result[:start], shortened, result[end:]])
193
+ total_removed += removed
194
+
195
+ return result, len(long_regions), total_removed
196
+
197
+
198
+ def main():
199
+ parser = argparse.ArgumentParser(
200
+ description="Reduce duration of harsh sibilant sounds in audio files"
201
+ )
202
+ parser.add_argument(
203
+ "--input-dir",
204
+ type=Path,
205
+ default=Path("wav"),
206
+ help="Input directory containing WAV files (default: wav)",
207
+ )
208
+ parser.add_argument(
209
+ "--output-dir",
210
+ type=Path,
211
+ default=Path("wav_deessed"),
212
+ help="Output directory for processed files (default: wav_deessed)",
213
+ )
214
+ parser.add_argument(
215
+ "--threshold",
216
+ type=float,
217
+ default=DETECTION_THRESHOLD,
218
+ help=f"Detection sensitivity 0-1 (default: {DETECTION_THRESHOLD})",
219
+ )
220
+ parser.add_argument(
221
+ "--max-duration",
222
+ type=float,
223
+ default=MAX_SIBILANT_DURATION * 1000,
224
+ help=f"Maximum sibilant duration in ms (default: {MAX_SIBILANT_DURATION * 1000})",
225
+ )
226
+ parser.add_argument(
227
+ "--crossfade",
228
+ type=float,
229
+ default=CROSSFADE_DURATION * 1000,
230
+ help=f"Crossfade duration in ms (default: {CROSSFADE_DURATION * 1000})",
231
+ )
232
+ parser.add_argument(
233
+ "--freq-low",
234
+ type=float,
235
+ default=SIBILANT_FREQ_LOW,
236
+ help=f"Lower frequency bound in Hz (default: {SIBILANT_FREQ_LOW})",
237
+ )
238
+ parser.add_argument(
239
+ "--freq-high",
240
+ type=float,
241
+ default=SIBILANT_FREQ_HIGH,
242
+ help=f"Upper frequency bound in Hz (default: {SIBILANT_FREQ_HIGH})",
243
+ )
244
+
245
+ args = parser.parse_args()
246
+
247
+ # Convert ms to seconds
248
+ max_duration = args.max_duration / 1000
249
+ crossfade_duration = args.crossfade / 1000
250
+
251
+ # Find input files
252
+ input_dir = args.input_dir
253
+ output_dir = args.output_dir
254
+
255
+ if not input_dir.exists():
256
+ print(f"Error: Input directory '{input_dir}' does not exist")
257
+ return 1
258
+
259
+ wav_files = list(input_dir.glob("*.wav"))
260
+ if not wav_files:
261
+ print(f"No WAV files found in '{input_dir}'")
262
+ return 1
263
+
264
+ # Create output directory
265
+ output_dir.mkdir(parents=True, exist_ok=True)
266
+
267
+ print(f"Processing {len(wav_files)} file(s)...")
268
+ print(f"Settings: threshold={args.threshold}, max_duration={args.max_duration}ms, "
269
+ f"freq_range={args.freq_low}-{args.freq_high}Hz")
270
+ print()
271
+
272
+ total_shortened = 0
273
+ total_time_removed = 0.0
274
+
275
+ for wav_file in tqdm(wav_files, desc="Processing files"):
276
+ # Load audio
277
+ samples, sr = sf.read(wav_file)
278
+
279
+ # Handle stereo by processing each channel
280
+ if samples.ndim == 2:
281
+ # Process each channel separately
282
+ processed_channels = []
283
+ file_shortened = 0
284
+ file_removed = 0
285
+
286
+ for ch in range(samples.shape[1]):
287
+ processed, shortened, removed = process_audio(
288
+ samples[:, ch],
289
+ sr,
290
+ args.freq_low,
291
+ args.freq_high,
292
+ args.threshold,
293
+ max_duration,
294
+ crossfade_duration,
295
+ MIN_GAP_DURATION,
296
+ )
297
+ processed_channels.append(processed)
298
+ file_shortened = max(file_shortened, shortened)
299
+ file_removed = max(file_removed, removed)
300
+
301
+ # Find minimum length and trim all channels to match
302
+ min_len = min(len(ch) for ch in processed_channels)
303
+ processed = np.column_stack([ch[:min_len] for ch in processed_channels])
304
+ else:
305
+ # Mono
306
+ processed, file_shortened, file_removed = process_audio(
307
+ samples,
308
+ sr,
309
+ args.freq_low,
310
+ args.freq_high,
311
+ args.threshold,
312
+ max_duration,
313
+ crossfade_duration,
314
+ MIN_GAP_DURATION,
315
+ )
316
+
317
+ # Save processed audio
318
+ output_path = output_dir / wav_file.name
319
+ sf.write(output_path, processed, sr)
320
+
321
+ if file_shortened > 0:
322
+ time_removed = file_removed / sr
323
+ total_shortened += file_shortened
324
+ total_time_removed += time_removed
325
+ tqdm.write(f" {wav_file.name}: shortened {file_shortened} sibilant(s), "
326
+ f"removed {time_removed*1000:.1f}ms")
327
+
328
+ print()
329
+ print(f"Done! Processed {len(wav_files)} file(s)")
330
+ print(f"Total: {total_shortened} sibilant(s) shortened, "
331
+ f"{total_time_removed*1000:.1f}ms removed")
332
+ print(f"Output saved to: {output_dir}/")
333
+
334
+ return 0
335
+
336
+
337
+ if __name__ == "__main__":
338
+ exit(main())
sibilant-reducer/uv.lock ADDED
The diff for this file is too large to render. See raw diff
 
sibilant-reducer/wav/YhIom1p-P-k_0225.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6fd481b1542f5104d9a3329126b412197c120b59cbbe523f143492bb5f840b0a
3
+ size 1598444
sibilant-reducer/wav/iGGDPZ0KeJk_0118.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ab3c9b8bbff4515fd5f67194e5809382d786498317d9bcc3d2d8781a522afb9
3
+ size 1596844
sibilant-reducer/wav/vJG48-st6bE_0055.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a210e587753bdb6c8e4ed53ae52bc6b76b2114a9eff50d5222db7918e2b6e12
3
+ size 1595244