File size: 1,639 Bytes
5f7dac2
 
 
 
 
 
 
 
d9be113
5f7dac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
license: cc0-1.0
---

# 張悦楷三國演義

Fork from [laubonghaudoi/zoengjyutgaai_saamgwokjinji](https://huggingface.co/datasets/laubonghaudoi/zoengjyutgaai_saamgwokjinji)

We found the original wav files are not splitted correctly, so we asked the author to provide the srt file and un-splitted wav files. We then re-split the wav files and align the srt file to the wav files. We also filtered some samples that are too short.

```python
subtitles = []
splits = librosa.effects.split(audio) # shape: (682, 2)

!mkdir -p dataset/zoengjyutgaai_saamgwokjinji/wavs

# split audio by srt time
for i, sub in enumerate(subs):
    chunk_start = sub.start.to_time()
    chunk_end = sub.end.to_time()
    chunk_start = ((chunk_start.minute * 60) + chunk_start.second) * sr
    chunk_end = ((chunk_end.minute * 60) + chunk_end.second) * sr

    # Find the closest split
    chunk_start = min(splits, key=lambda x: abs(x[0] - chunk_start))[0]
    chunk_end = min(splits, key=lambda x: abs(x[1] - chunk_end))[1]

    chunk = audio[chunk_start:chunk_end]
    wav_file = f"001_{i:03}.wav"

    # resample, since bert-vits2 training only support 44.1k 
    try:
        chunk = librosa.resample(chunk, sr, 44100)
    except:
        print(f"Error resampling {wav_file}")
        continue

    subtitles.append({ 'path': wav_file, 'speaker': 'zoengjyutgaai', 'language': 'YUE', 'text': sub.text })

    # export audio
    sf.write(f"dataset/zoengjyutgaai_saamgwokjinji/wavs/{wav_file}", chunk, 44100, subtype='PCM_16')

df = pd.DataFrame(subtitles)
df.to_csv("dataset/zoengjyutgaai_saamgwokjinji/001.csv", index=False, sep='|', header=False)
```