fasdfsa commited on
Commit
fb7f2da
·
1 Parent(s): 910a725
KotobaASRLLM/convert_ts_to_wav.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import subprocess
4
+ import re
5
+
6
+ def sort_key(filename):
7
+ # Extract number from filename like "tbs-38532.ts"
8
+ match = re.search(r'(\d+)', filename)
9
+ if match:
10
+ return int(match.group(1))
11
+ return filename
12
+
13
+ def main():
14
+ # Base directory containing the script
15
+ base_dir = os.path.dirname(os.path.abspath(__file__))
16
+ temp_video_dir = os.path.join(base_dir, "TempVideo")
17
+
18
+ # Check if directory exists
19
+ if not os.path.exists(temp_video_dir):
20
+ print(f"Error: Directory {temp_video_dir} does not exist.")
21
+ return
22
+
23
+ # Find all .ts files
24
+ ts_files = glob.glob(os.path.join(temp_video_dir, "*.ts"))
25
+ if not ts_files:
26
+ print("No .ts files found in TempVideo directory.")
27
+ return
28
+
29
+ # Sort files to ensure correct order
30
+ ts_files.sort(key=lambda x: sort_key(os.path.basename(x)))
31
+
32
+ wav_files = []
33
+
34
+ print(f"Found {len(ts_files)} .ts files. Starting conversion...")
35
+
36
+ for ts_file in ts_files:
37
+ wav_file = os.path.splitext(ts_file)[0] + ".wav"
38
+ wav_files.append(wav_file)
39
+
40
+ # Check if wav already exists to avoid re-encoding (optional, but good for retries)
41
+ # For now, we overwrite as per request implying a fresh run, or use -y in ffmpeg
42
+
43
+ cmd = [
44
+ "ffmpeg",
45
+ "-y", # Overwrite output files
46
+ "-i", ts_file,
47
+ "-ar", "16000",
48
+ "-ac", "1",
49
+ "-c:a", "pcm_s16le",
50
+ wav_file
51
+ ]
52
+
53
+ print(f"Converting {os.path.basename(ts_file)} to {os.path.basename(wav_file)}...")
54
+ try:
55
+ subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
56
+ except subprocess.CalledProcessError as e:
57
+ print(f"Error converting {ts_file}: {e}")
58
+ return
59
+ except FileNotFoundError:
60
+ print("Error: ffmpeg not found. Please ensure ffmpeg is installed and in your PATH.")
61
+ return
62
+
63
+ print("All conversions complete. Merging files...")
64
+
65
+ # Create concat list file
66
+ concat_list_path = os.path.join(temp_video_dir, "concat_list.txt")
67
+ with open(concat_list_path, "w", encoding="utf-8") as f:
68
+ for wav_file in wav_files:
69
+ # Escape single quotes in path if necessary (though simple filenames usually don't need it)
70
+ # ffmpeg requires paths to be escaped
71
+ safe_path = wav_file.replace("'", "'\\''")
72
+ f.write(f"file '{safe_path}'\n")
73
+
74
+ merged_output_path = os.path.join(temp_video_dir, "merged_output.wav")
75
+
76
+ # Merge command
77
+ merge_cmd = [
78
+ "ffmpeg",
79
+ "-y",
80
+ "-f", "concat",
81
+ "-safe", "0",
82
+ "-i", concat_list_path,
83
+ "-c", "copy",
84
+ merged_output_path
85
+ ]
86
+
87
+ try:
88
+ subprocess.run(merge_cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
89
+ print(f"Successfully merged into: {merged_output_path}")
90
+ except subprocess.CalledProcessError as e:
91
+ print(f"Error merging files: {e}")
92
+
93
+ # Clean up list file
94
+ if os.path.exists(concat_list_path):
95
+ os.remove(concat_list_path)
96
+
97
+ if __name__ == "__main__":
98
+ main()
KotobaASRLLM/readme.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ see 深入理解神经网络:从逻辑回归到CNN.md -> kotoba-whisper-v2.0-ggml
4
+
5
+ see https://huggingface.co/kotoba-tech/kotoba-whisper-v2.0-ggml
6
+
7
+ see https://github.com/ggerganov/whisper.cpp
8
+
9
+ see https://github.com/kotoba-tech/tts_eval/blob/main/tts_eval/metric_asr.py kotoba-whisper-v2.0 + 语音相似度
10
+
11
+ see huggingface_echodict\CefSharpPlayer\CefSharpPlayer\readme.txt IPTV 输出每个流的信息
12
+
13
+ see huggingface_echodict\IPTV2\readme.txt 边下载边推流 + 伪推流
14
+
15
+ see huggingface_echodict\IPTV2\TempVideo 下载视频
16
+
17
+
18
+
19
+ cd kotoba-whisper-v2.0-ggml/whisper.cpp \
20
+ && make -j
21
+
22
+
23
+ ./whisper-cli.exe -m ggml-kotoba-whisper-v2.0.bin -l ja -f 60s.wav --output-file transcription --output-json
24
+ ./whisper-cli.exe -m ggml-kotoba-whisper-v2.0.bin -l ja -f segment_0001.wav --output-file transcription --output-json
25
+ 成功识别
26
+
27
+
28
+ ffprobe -print_format json -show_streams KotobaASRLLM/TempVideo/tbs-38532.ts
29
+ 输出每个流的信息
30
+ Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 130 kb/s, start 62720.902889
31
+
32
+ ffmpeg -i KotobaASRLLM/TempVideo/tbs-38532.ts -c:a pcm_s16le -ar 16000 -ac 1 -y KotobaASRLLM/TempVideo/tbs-38532.wav
33
+ 转成 wav
34
+ 采样率 : 16000 Hz (已调整为 ASR 常用标准)
35
+ 声道 : 单声道 (mono) (已调整为 ASR 常用标准)
36
+
37
+ Note that it runs only with 16-bit WAV files, so make sure to convert your input before running the tool. For example, you can use ffmpeg like this:
38
+
39
+ ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav
40
+
41
+
42
+ python convert_ts_to_wav.py
43
+ 调用 ffmpeg 把这目录下的所有 ts 视频转成指定格式的 wav 音频,最后再合并所有 wav 音频片段成为一个长音频