audiosub 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of audiosub might be problematic. Click here for more details.
- audiosub-0.1.0/.github/workflows/publish.yml +32 -0
- audiosub-0.1.0/.gitignore +13 -0
- audiosub-0.1.0/.python-version +1 -0
- audiosub-0.1.0/PKG-INFO +53 -0
- audiosub-0.1.0/README.md +42 -0
- audiosub-0.1.0/pyproject.toml +21 -0
- audiosub-0.1.0/src/audiosub/__init__.py +69 -0
- audiosub-0.1.0/tests/smoke_test.py +20 -0
- audiosub-0.1.0/uv.lock +1021 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: "Publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
# Publish on any tag starting with a `v`, e.g., v0.1.0
|
|
7
|
+
- v*
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
run:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: pypi
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write
|
|
16
|
+
contents: read
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout
|
|
19
|
+
uses: actions/checkout@v5
|
|
20
|
+
- name: Install uv
|
|
21
|
+
uses: astral-sh/setup-uv@v6
|
|
22
|
+
- name: Install Python 3.12
|
|
23
|
+
run: uv python install 3.12
|
|
24
|
+
- name: Build
|
|
25
|
+
run: uv build
|
|
26
|
+
# Check that basic features work and we didn't miss to include crucial files
|
|
27
|
+
- name: Smoke test (wheel)
|
|
28
|
+
run: uv run --isolated --no-project --with dist/*.whl python tests/smoke_test.py
|
|
29
|
+
- name: Smoke test (source distribution)
|
|
30
|
+
run: uv run --isolated --no-project --with dist/*.tar.gz python tests/smoke_test.py
|
|
31
|
+
- name: Publish
|
|
32
|
+
run: uv publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
audiosub-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: audiosub
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A command-line tool for generating subtitles from audio file using mlx-whisper
|
|
5
|
+
Project-URL: Homepage, https://github.com/huccihuang/audiosub
|
|
6
|
+
Project-URL: Repository, https://github.com/huccihuang/audiosub
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Requires-Dist: click>=8.3.0
|
|
9
|
+
Requires-Dist: mlx-whisper>=0.4.3
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# audiosub
|
|
13
|
+
|
|
14
|
+
一个基于 mlx-whisper 的命令行工具,用于将音频文件转换为字幕文件。
|
|
15
|
+
|
|
16
|
+
## 特点
|
|
17
|
+
|
|
18
|
+
- **资源占用小**:基于 mlx-whisper,专为 Apple Silicon 优化
|
|
19
|
+
- **转换速度快**:利用 Apple Metal 加速,处理速度快
|
|
20
|
+
- **准确度高**:使用 OpenAI Whisper 模型,支持多种语言
|
|
21
|
+
- **使用简单**:命令行操作,一键生成字幕文件
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
|
|
25
|
+
- Python 3.12+
|
|
26
|
+
- macOS
|
|
27
|
+
- uv
|
|
28
|
+
|
|
29
|
+
## 使用方法
|
|
30
|
+
|
|
31
|
+
通过 uv 的 `uvx` 命令安装并使用。
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uvx asub audio.mp3
|
|
35
|
+
# 将在当前目录生成 audio.srt 字幕文件
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 注意事项
|
|
39
|
+
|
|
40
|
+
- **仅支持 macOS**:由于使用了 mlx 库,本工具仅能在 macOS 系统上运行
|
|
41
|
+
- **Apple Silicon 优化**:在 Apple Silicon (M1/M2/M3) 芯片上性能最佳
|
|
42
|
+
- **支持的音频格式**:支持常见的音频格式,如 MP3、WAV、M4A 等
|
|
43
|
+
- **首次运行**:首次使用时会自动下载 Whisper 模型,请确保网络连接正常
|
|
44
|
+
|
|
45
|
+
## 依赖
|
|
46
|
+
|
|
47
|
+
- Python 3.12+
|
|
48
|
+
- mlx-whisper
|
|
49
|
+
- click
|
|
50
|
+
|
|
51
|
+
## 许可证
|
|
52
|
+
|
|
53
|
+
MIT
|
audiosub-0.1.0/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# audiosub
|
|
2
|
+
|
|
3
|
+
一个基于 mlx-whisper 的命令行工具,用于将音频文件转换为字幕文件。
|
|
4
|
+
|
|
5
|
+
## 特点
|
|
6
|
+
|
|
7
|
+
- **资源占用小**:基于 mlx-whisper,专为 Apple Silicon 优化
|
|
8
|
+
- **转换速度快**:利用 Apple Metal 加速,处理速度快
|
|
9
|
+
- **准确度高**:使用 OpenAI Whisper 模型,支持多种语言
|
|
10
|
+
- **使用简单**:命令行操作,一键生成字幕文件
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- Python 3.12+
|
|
15
|
+
- macOS
|
|
16
|
+
- uv
|
|
17
|
+
|
|
18
|
+
## 使用方法
|
|
19
|
+
|
|
20
|
+
通过 uv 的 `uvx` 命令安装并使用。
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uvx asub audio.mp3
|
|
24
|
+
# 将在当前目录生成 audio.srt 字幕文件
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 注意事项
|
|
28
|
+
|
|
29
|
+
- **仅支持 macOS**:由于使用了 mlx 库,本工具仅能在 macOS 系统上运行
|
|
30
|
+
- **Apple Silicon 优化**:在 Apple Silicon (M1/M2/M3) 芯片上性能最佳
|
|
31
|
+
- **支持的音频格式**:支持常见的音频格式,如 MP3、WAV、M4A 等
|
|
32
|
+
- **首次运行**:首次使用时会自动下载 Whisper 模型,请确保网络连接正常
|
|
33
|
+
|
|
34
|
+
## 依赖
|
|
35
|
+
|
|
36
|
+
- Python 3.12+
|
|
37
|
+
- mlx-whisper
|
|
38
|
+
- click
|
|
39
|
+
|
|
40
|
+
## 许可证
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "audiosub"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A command-line tool for generating subtitles from audio file using mlx-whisper"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"click>=8.3.0",
|
|
13
|
+
"mlx-whisper>=0.4.3",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
asub = "audiosub:main"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/huccihuang/audiosub"
|
|
21
|
+
Repository = "https://github.com/huccihuang/audiosub"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import click
|
|
3
|
+
import mlx_whisper
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def format_time(time):
|
|
7
|
+
'''将float格式的时间转换为字幕要求的格式 hh:mm:ss,ms'''
|
|
8
|
+
hours = int(time // 3600)
|
|
9
|
+
minutes = int((time % 3600) // 60)
|
|
10
|
+
seconds = int(time % 60)
|
|
11
|
+
milliseconds = int((time - int(time)) * 1000)
|
|
12
|
+
return f"{hours:02d}:{minutes:02d}:{seconds:02d},{milliseconds:03d}"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def audio_to_subtitle(audio_file_path, output_file_path):
|
|
16
|
+
'''将音频文件转换为字幕文件'''
|
|
17
|
+
|
|
18
|
+
# 获取词级时间戳
|
|
19
|
+
result = mlx_whisper.transcribe(
|
|
20
|
+
audio_file_path,
|
|
21
|
+
word_timestamps=True
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# 存放到文件中
|
|
25
|
+
with open(output_file_path, "w") as f:
|
|
26
|
+
for idx, segment in enumerate(result["segments"]):
|
|
27
|
+
start_time = format_time(segment["start"])
|
|
28
|
+
end_time = format_time(segment["end"])
|
|
29
|
+
f.write(
|
|
30
|
+
f"{idx + 1}\n"
|
|
31
|
+
f"{start_time} --> {end_time}\n"
|
|
32
|
+
f"{segment['text']}\n\n"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@click.command()
|
|
37
|
+
@click.argument('audio_file', type=click.Path(exists=True))
|
|
38
|
+
def main(audio_file):
|
|
39
|
+
"""将音频文件转换为字幕文件
|
|
40
|
+
|
|
41
|
+
使用示例:
|
|
42
|
+
mksub audio.mp3
|
|
43
|
+
|
|
44
|
+
将在当前目录生成 audio.srt 字幕文件
|
|
45
|
+
"""
|
|
46
|
+
# 检查文件是否存在
|
|
47
|
+
if not os.path.exists(audio_file):
|
|
48
|
+
click.echo(f"错误:文件 '{audio_file}' 不存在", err=True)
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
# 获取输入文件的基本名称(不含扩展名)
|
|
52
|
+
base_name = os.path.splitext(os.path.basename(audio_file))[0]
|
|
53
|
+
|
|
54
|
+
# 在当前工作目录生成输出文件
|
|
55
|
+
output_file = f"{base_name}.srt"
|
|
56
|
+
|
|
57
|
+
click.echo(f"正在处理音频文件: {audio_file}")
|
|
58
|
+
click.echo(f"输出字幕文件: {output_file}")
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
audio_to_subtitle(audio_file, output_file)
|
|
62
|
+
click.echo(f"✓ 字幕文件已生成: {output_file}")
|
|
63
|
+
except Exception as e:
|
|
64
|
+
click.echo(f"错误:处理失败 - {str(e)}", err=True)
|
|
65
|
+
raise
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Basic smoke test to verify the package was built correctly."""
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import audiosub
|
|
6
|
+
print("✓ Package import successful")
|
|
7
|
+
except ImportError as e:
|
|
8
|
+
print(f"✗ Package import failed: {e}")
|
|
9
|
+
exit(1)
|
|
10
|
+
|
|
11
|
+
# Test that main function exists
|
|
12
|
+
import audiosub
|
|
13
|
+
|
|
14
|
+
if hasattr(audiosub, 'main'):
|
|
15
|
+
print("✓ Main function exists")
|
|
16
|
+
else:
|
|
17
|
+
print("✗ Main function not found")
|
|
18
|
+
exit(1)
|
|
19
|
+
|
|
20
|
+
print("✓ Smoke test passed")
|