47z commited on
Commit
7783c21
·
verified ·
1 Parent(s): 544db41

Remove legacy file

Browse files
Files changed (1) hide show
  1. make_kimi_train.py +0 -107
make_kimi_train.py DELETED
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Step 2: metadata.tsv → FLAC-to-WAV conversion + metadata_kimi_train.jsonl
4
-
5
- WARNING: This script converts all .flac files to .wav IN-PLACE and deletes the .flac.
6
- WAV files are approximately 2-3x larger than FLAC.
7
- Purpose: produce training data in Kimi-Audio conversation format.
8
-
9
- Output: metadata_kimi_train.jsonl (same directory as this script)
10
- Each pair produces two entries:
11
- 1. EN→ZH: user gives EN audio, assistant responds with ZH audio + ZH text
12
- 2. ZH→EN: user gives ZH audio, assistant responds with EN audio + EN text
13
- """
14
-
15
- import csv
16
- import json
17
- import os
18
- import soundfile as sf
19
- from tqdm import tqdm
20
-
21
- BASE_DIR = os.path.dirname(__file__)
22
- INPUT_TSV = os.path.join(BASE_DIR, "metadata.tsv")
23
- OUTPUT_JSONL = os.path.join(BASE_DIR, "metadata_kimi_train.jsonl")
24
-
25
-
26
- def flac_to_wav(flac_path: str) -> str:
27
- """Convert a .flac file to .wav in-place (deletes .flac). Returns .wav path."""
28
- wav_path = flac_path[:-5] + ".wav"
29
- data, sr = sf.read(flac_path)
30
- sf.write(wav_path, data, sr)
31
- os.remove(flac_path)
32
- return wav_path
33
-
34
-
35
- def flac_rel_to_wav_rel(p: str) -> str:
36
- return p[:-5] + ".wav" if p.endswith(".flac") else p
37
-
38
-
39
- def main():
40
- with open(INPUT_TSV, "r", encoding="utf-8") as f:
41
- rows = list(csv.DictReader(f, delimiter="\t"))
42
- print(f"Loaded {len(rows)} pairs from {INPUT_TSV}")
43
- print("Converting FLAC → WAV (in-place) and writing metadata_kimi_train.jsonl ...")
44
-
45
- ok = skip = fail = 0
46
- out_f = open(OUTPUT_JSONL, "w", encoding="utf-8")
47
-
48
- for row in tqdm(rows, unit="pairs"):
49
- zh_flac = os.path.join(BASE_DIR, row["zh_path"])
50
- en_flac = os.path.join(BASE_DIR, row["en_path"])
51
- zh_text = row["zh_text"]
52
- en_text = row["en_text"]
53
-
54
- # Convert FLAC → WAV for both files
55
- converted = {}
56
- for key, flac_abs in [("zh", zh_flac), ("en", en_flac)]:
57
- wav_abs = flac_abs[:-5] + ".wav"
58
- if os.path.exists(wav_abs):
59
- converted[key] = wav_abs
60
- elif os.path.exists(flac_abs):
61
- try:
62
- converted[key] = flac_to_wav(flac_abs)
63
- except Exception as e:
64
- print(f"\n FAILED converting {flac_abs}: {e}")
65
- fail += 1
66
- break
67
- else:
68
- print(f"\n MISSING: {flac_abs}")
69
- fail += 1
70
- break
71
- else:
72
- # Both converted successfully — write two conversation entries
73
- en_rel = flac_rel_to_wav_rel(row["en_path"])
74
- zh_rel = flac_rel_to_wav_rel(row["zh_path"])
75
-
76
- # EN → ZH
77
- out_f.write(json.dumps({
78
- "task_type": "s-s",
79
- "conversation": [
80
- {"role": "user", "message_type": "text", "content": "Translate the given English speech into Chinese while preserving its expressiveness."},
81
- {"role": "user", "message_type": "audio", "content": en_rel},
82
- {"role": "assistant", "message_type": "audio-text", "content": [zh_rel, zh_text]},
83
- ]
84
- }, ensure_ascii=False) + "\n")
85
-
86
- # ZH → EN
87
- out_f.write(json.dumps({
88
- "task_type": "s-s",
89
- "conversation": [
90
- {"role": "user", "message_type": "text", "content": "Translate the given Chinese speech into English while preserving its expressiveness."},
91
- {"role": "user", "message_type": "audio", "content": zh_rel},
92
- {"role": "assistant", "message_type": "audio-text", "content": [en_rel, en_text]},
93
- ]
94
- }, ensure_ascii=False) + "\n")
95
-
96
- ok += 1
97
- continue
98
-
99
- skip += 1
100
-
101
- out_f.close()
102
- print(f"\nDone: {ok} pairs converted, {skip} skipped/missing, {fail} errors")
103
- print(f"Output: {OUTPUT_JSONL} ({ok * 2} total conversation entries)")
104
-
105
-
106
- if __name__ == "__main__":
107
- main()