Skip to content

Commit

Permalink
修复打包的问题;完善文档
Browse files Browse the repository at this point in the history
  • Loading branch information
AuYang261 committed Apr 9, 2024
1 parent cce3581 commit 1c4da21
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ build/
dist/
*.spec
whisper_models/
release-downloader/
release_*/
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## 使用:下载指定课程

[下载并解压](https://github.com/AuYang261/BIT_yanhe_download/releases/latest/download/yanhe.zip)
[下载并解压](https://github.com/AuYang261/BIT_yanhe_download/releases/latest/download/release_downloader.zip)

[延河课堂 (yanhekt.cn)](https://www.yanhekt.cn/recordCourse)中找到想下载的课程,以链接为https://www.yanhekt.cn/course/40524 的课程为例,复制地址栏最后的五位编号40524。注意是课程列表的链接(以`yanhekt.cn/course/五位编号`开头),不是视频界面的链接(以`yanhekt.cn/session/六位编号`开头)。

Expand All @@ -32,17 +32,17 @@

最好使用GPU运行,否则速度较慢,依赖见[下文](#依赖)

下载[生成字幕可执行文件](),保存在上述解压的目录中,如下所示:
下载[字幕生成程序gen_caption](https://github.com/AuYang261/BIT_yanhe_download/releases/latest),由于程序比较大,采用了分卷压缩发布。全部下载并解压,得到一个`gen_caption.exe`可执行文件,保存在上述`release_downloader.zip`解压的目录中,和保存视频的目录`output/`同级,如下所示:

![image-20240409105228362](md/README/image-20240409105228362.png)

下载完视频后,双击运行`gen_caption.exe`(文件较大,需要等一会),输入数字选择视频,回车:
下载完视频后,双击运行`gen_caption.exe`(文件较大,需要等一会),输入数字选择视频,回车。再输入数字选择使用多大的模型,越往下效果越好,但所需时间也越长,默认使用base模型。第一次使用会自动下载模型(几百M),请耐心等待。如下所示

![image-20240409103224309](md/README/image-20240409103224309.png)
![image-20240409131033038](md/README/image-20240409131033038.png)

等待程序运行完成,生成的字幕文件为`.srt`格式,与视频文件在同级目录下,用支持字幕的播放器(如potplayer)打开视频即可看到带字幕的视频。

*tips: 语音转文字所需的时间较长,可以先观看视频,字幕生成好了再重新打开视频享受字幕。使用GPU大约需要几分钟,若无GPU则不建议使用本项目提供的字幕功能,可自行寻找其他生成字幕的工具*
*tips: 语音转文字所需的时间较长,可以先观看视频,字幕生成好了再重新打开视频享受字幕。使用GPU大约需要几分钟,不使用GPU则需要更长时间*

## 依赖

Expand Down Expand Up @@ -109,4 +109,4 @@ pyinstaller --clean .\gen_caption.spec

![image-20240409095831766](md/README/image-20240409095831766.png)

可将项目`hooks`目录下的`hook-whisper.py``hook-zhconv.py`文件复制到pyinstaller的hook目录下(通常在`python根目录\Lib\site-packages\PyInstaller\hooks`),参考[这个](https://blog.csdn.net/qq_42324086/article/details/118280341)
解决方法参考[这个](https://blog.csdn.net/qq_42324086/article/details/118280341),将项目`hooks`目录下的`hook-whisper.py``hook-zhconv.py`文件复制到pyinstaller的hook目录下(通常在`python根目录\Lib\site-packages\PyInstaller\hooks`),。
21 changes: 18 additions & 3 deletions gen_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,37 @@ def main():
video_paths.append(sys.argv[1])
else:
files = []
for dirpath, dirnames, filenames in os.walk("output/"):
for dirpath, dirnames, filenames in os.walk("."):
for filename in filenames:
if filename.endswith(".mp4"):
files.append(os.path.join(dirpath, filename).replace("\\", "/"))
for i, f in enumerate(files):
print(f"[{i}]: ", f)
input_list = eval("[" + input("select a video file by input a num: ") + "]")
input_list = eval(
"[" + input("select a video file by input a num(split with ','): ") + "]"
)
for i in input_list:
video_paths.append(files[i])
print("selected video files:", video_paths)
models = []
for model in whisper.available_models():
if ".en" in model:
continue
print(f"[{len(models)}]: ", model)
models.append(model)
model_index = input("select a model by input a num(default 'base'): ")
try:
model_name = models[eval(model_index)]
except:
model_name = "base"
print("selected model:", model_name)

for video_path in video_paths:
audio_path = video_path.replace("mp4", "m4a")
cmd = f'ffmpeg -i "{video_path}" -vn -ar {whisper.audio.SAMPLE_RATE} "{audio_path}"'
os.system(cmd)

model = whisper.load_model("base", download_root="whisper_models/")
model = whisper.load_model(model_name, download_root="whisper_models/")

start = time.time()
result = model.transcribe(audio_path, verbose=False, language="zh")
Expand Down
2 changes: 1 addition & 1 deletion hooks/hook-zhconv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files("whisper")
datas = collect_data_files("zhconv")
Binary file removed md/README/image-20240409103224309.png
Binary file not shown.
Binary file added md/README/image-20240409131033038.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c4da21

Please sign in to comment.