Created
February 6, 2024 05:59
-
-
Save AWtnb/d48ad8fd24725c6dd6939ef2175b222d to your computer and use it in GitHub Desktop.
Whisperでローカル文字起こし
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
from pathlib import Path | |
import whisper | |
def main(infile: str) -> None: | |
in_path = Path(infile) | |
out_path = in_path.with_name(in_path.stem + ".txt") | |
model = whisper.load_model("medium") # base < small < medium < large | |
result = model.transcribe(infile, verbose=True, language="ja") | |
lines = [] | |
for segment in result["segments"]: | |
lines.append(segment["text"]) | |
Path(out_path).write_text(os.linesep.join(lines), encoding="utf-8") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("infile", type=str) | |
args = parser.parse_args() | |
main(args.infile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment