Skip to content

Commit

Permalink
feat: allow CLI tool to toggle between devices
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Sep 16, 2023
1 parent 3e7b018 commit c9cd7f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ poetry install --without=server
You can run the transcriber as a CLI tool.

```bash
python transcribe.py -f ~/Downloads/audio.mp3 -t srt -o ./result.srt
python transcribe.py -f ~/Downloads/audio.mp3 -t srt -o ./result.srt --cuda
```

```yaml
usage: transcribe.py [-h] -f -t -o
usage: transcribe.py [-h] [-c] -f -t -o

Transcribe a compatible audio/video file into a chosen caption file

Expand All @@ -54,4 +54,5 @@ options:
-f, --file the file path to a compatible audio/video
-t, --type the chosen caption file format
-o, --output the output file path
-c, --cuda whether to use CUDA for inference
```
6 changes: 6 additions & 0 deletions transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Arguments(NamedTuple):
file: str
type: Literal['srt']
output: str
cuda: bool


def parse_args() -> tuple[Arguments, list[str]]:
Expand All @@ -26,6 +27,7 @@ def parse_args() -> tuple[Arguments, list[str]]:
unknown (list[str]) : the unknown arguments
"""
parser = ArgumentParser(description='Transcribe a compatible audio/video file into a chosen caption file')
parser.add_argument('-c', '--cuda', action='store_true', help='whether to use CUDA for inference')
parser.add_argument('-f', '--file', type=str, required=True, metavar='', help='the file path to a compatible audio/video')
parser.add_argument('-t', '--type', type=str, required=True, metavar='', help='the chosen caption file format')
parser.add_argument('-o', '--output', type=str, required=True, metavar='', help='the output file path')
Expand All @@ -39,6 +41,10 @@ def main():
-------
"""
args, _ = parse_args()

if args.cuda:
Transcriber.toggle_device()

transcription = Transcriber.transcribe(args.file, args.type)

with open(args.output, 'w', encoding='utf-8') as file:
Expand Down

0 comments on commit c9cd7f9

Please sign in to comment.