A Python script to extract text from audio/video and translate subtitle using Google Cloud, DeepL APIs.
OpenAI์ Whisper์ ์๋ง์ ์ํด ์กฐ๊ธ ๋ณํํ stable-ts ๋ฐ faster-whisper๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋์ค AI ์์ฑ ์ธ์ ๋ฐ ๋ฒ์ญ ๊ณผ์ ์ ์๋ํํ๊ธฐ ์ํ ํ์ด์ฌ ํ๋ก๊ทธ๋จ์ ๋๋ค.
์ด ํ๋ก๊ทธ๋จ์ ๋น๋์ค๋ก๋ถํฐ ์๋ง์ ๋ง๋ค๊ธฐ ์ํด ์์ ์์ฑ์ธ์ ๋ฐ ๋ฒ์ญ ๊ธฐ๋ฅ์ ๊ฒฐํฉํ์ฌ ์์ ์ด ํธ๋ฆฌํ๋๋ก ๊ตฌ์ฑํ์ต๋๋ค.
-
2025-02-16 subtitle-translator.py๋ .SRT๊ฐ ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ ๋ฒ์ญ๋ง ํ๊ธฐ ์ํ์ฌ ์ถ๊ฐํ์์ต๋๋ค. (python .\subtitle-translator.py --source ja --target ko D:\temp\ja.srt ์ ๊ฐ์ด ํ์ฉํ ์ ์์ต๋๋ค. ํน์ [๋จ์ผ exe๋ก ๋ง๋ค๊ธฐ] ํญ๋ชฉ์ ์ฐธ๊ณ ํ์ฌ .exe๋ก ๋ง๋ค๋ฉด ์ข๋ ํธ๋ฆฌํ๊ฒ ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.)
-
2025-01-01 faster-whisper๊ฐ ์๋ง ์ ์ฅ์ค๋ฅ๊ฐ ๋๋ ๊ฒ์ ์์ ํ์ต๋๋ค. ๋ฒ์ญ ํ ํ๋์ ์๋ง ์์ ๊ฐ์ ๋จ์ด๊ฐ ๊ณต๋ฐฑ์ด๋ ์ฝค๋ง๋ก 10๊ฐ ์ด์ ์ค๋ณต ํ์๋๋ฉด ์๋ง์ ์ญ์ ํ๋๋ก ํ์ต๋๋ค. ๋จ์ข ๋ deepl-rapidapi ๊ด๋ จ ๋ด์ฉ์ ์ญ์ ํ์ต๋๋ค. faster-whisper๋ https://github.com/Purfview/whisper-standalone-win ์ด์ฉํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. ์ถ๊ฐ ์ต์ ์ผ๋ก -m large-v2 --sentence -vad true --vad_method pyannote_v3 --compute_type=float16 --no_repeat_ngram_size 4 --ff_mdx_kim2 -hst 4 -bo 10 --ff_speechnorm ์ต์ ์ ์ฌ์ฉํ๋ฉด ์ข๋ค๊ณ ํฉ๋๋ค. --compute_type์ PC์ GPUํ๊ฒฝ์ ๋ง๊ฒ int8๋ก ๋ฐ๊พธ๊ฑฐ๋ -m medium์ผ๋ก ๋ฐ๊พธ๋ฉด ๋ฉ๋๋ค. -l ja ์ต์ ์ผ๋ก ์ผ๋ณธ์ด๋ฅผ ์ง์ ํด ์ค ์ ์์ต๋๋ค.
-
2024-12-07 Python์ ๋ฒ์ 3.13.1์ Whisper์ค์น ์ค์ wheel ์ค๋ฅ๊ฐ ๋์์ต๋๋ค. ์ผ๋จ 3.11.9๋ฅผ ์ฐ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค.
-
2024-11-29 ๋ง์ฝ ์คํ ์ค์ NumPy 2.0์ด๋ผ์ ์๋๋ค๋ ์ค๋ฅ๊ฐ ๋์ค๋ฉด, pip uninstall numpy ๋ฐ pip install "numpy<2.0" ๋ฅผ ํตํด ํด๊ฒฐํ ์ ์์ต๋๋ค.
-
2023-11-17 app.py์ ์น ํ๋ฉด ๊ตฌ์ฑ์ ๋ณ๊ฒฝํ๊ณ , ์ฌ๋ฌ ๊ฐ์ MP3๋ฅผ ์ฒ๋ฆฌํ ์ ์๊ฒ ํ์์ต๋๋ค. 20231117a ๋ฒ์ ์ ์๋์ฐ11, WSL Ubuntu, Colab์์ ํ ์คํธ ํ์ต๋๋ค. ๋ค๋ง, Colab์์๋ ์ฒ์ ํ๋ฒ๋ง ์ ์ ์๋ํด์ "๋ฐํ์ ๋ค์ ์์"์ ํ ํ ๋ค์ !python app.py๋ฅผ ํด์ค์ผ ํฉ๋๋ค.
-
2023-11-12 ์๋ WebUI(Gradio.app)๋ก ๋ง๋ app.py๋ Colab์์๋ ํ ์คํธ ํด ๋ณผ ์ ์์ต๋๋ค. ์งํ ๊ณผ์ ์ ์ค์๊ฐ์ผ๋ก ๋ณด์ฌ์ฃผ๋ ๊ธฐ๋ฅ์ ์์ ์ค์ ๋๋ค...
-
2023-11-11 WebUI๋ฅผ ์ํ ์์ฃผ ๊ธฐ์ด์ ์ธ ์ฑ์ ๋ง๋ค์ด ๋ณด์์ต๋๋ค. ๋ช ๋ นํ๋กฌํํธ๋ ํ์์์์ venv ํ๊ฒฝ์ ์คํ(activate.bat or activate.ps1)ํ ์ํ์์ pip install gradio๋ฅผ ํ๋ฒ ํด์ค ํ python app.py๋ฅผ ์คํํ๊ณ ๋งํฌ๋ฅผ Ctrl ๋๋ฅธ ์ฑ๋ก ๋ง์ฐ์ค ํด๋ฆญํด์ฃผ์๋ฉด ๋ฉ๋๋ค. ์์ ํด๋๋ก mp4๋ฅผ ๋ณต์ฌํ์ฌ ์์ ํ๊ฒ ๋์ด ์์ด ์ค๋ ๊ฑธ๋ฆฌ๋ฏ๋ก ffmpeg -i .\input.mp4 -vn -ab 128k .\output.mp3 ๋ฅผ ํตํด mp3๋ก ๋ง๋ค์ด ์ค ํ ์์ ํ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค.
-
2023-11-09 ์๋์ฐ์์๋ ๋ช ๋ นํ๋กฌํํธ์ฉ ๋ฐฐ์นํ์ผ์ธ install_venv.bat๋ฅผ ์คํํ์ฌ ํ์ด์ฌ venv ํ๊ฒฝ์ ์ฝ๊ฒ ์ค์นํ ์ ์์ต๋๋ค(์ฃผ์: ์๋ ์ค์น ์ค๋ช ์ค 3 ~ 5๋ฒ์ ๋ด์ฉ์ ํด๋นํฉ๋๋ค. ๊ทธ ์ด์ ๊ณผ ์ดํ ๋จ๊ณ๋ ์ง์ ์์ ํ์ ์ผ ํฉ๋๋ค.)
-
2023-11-08 Google Colab์์ ์คํํด ๋ณผ ์ ์๋๋ก .ipynb ํ์ผ์ ์ถ๊ฐํ์์ต๋๋ค. Colab์์๋ github์์ ๋ถ๋ฌ์จ ๊ฒฝ์ฐ ์ฌ๋ณธ์ผ๋ก ์ ์ฅ ํ ํ์ ์์ ์ด ๊ฐ๋ฅํ๋ฏ๋ก DEEPL_API_KEY ๊ฐ์ ๋ฃ์ด ์ค ์ ์๊ณ ์๋ง ์ถ์ถ ํ ๋ฒ์ญ๊น์ง ์งํํ ์ ์์ต๋๋ค. ๋ฃ์ง ์์๋ ์๋ง ์ถ์ถ์ ๊ฐ๋ฅํฉ๋๋ค. audio_langugate์ subtitle_language ๊ฐ์ ์ ์ ํ ๋ฐ๊พธ๋ฉด ๋ฉ๋๋ค(ko, en, ja, fr, cn ๋ฑ๋ฑ).
-
2023-08-27 faster-whisper ์ง์ ์ถ๊ฐ๋ก ์ ์ VRAM(์: MX150 2GB)์ ๊ฐ์ง ๋ ธํธ๋ถ์์๋ medium๋ชจ๋ธ ๊ฐ๋์ด ๊ฐ๋ฅ(๊ณต์ VRAM์ด ์๋ ๊ฒฝ์ฐ)ํฉ๋๋ค. ๋ค๋ง, cuDNN ๋ฐ cuBLAS๊ฐ ํ์ํฉ๋๋ค. Quantization๋ก int8์ ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ์ง์ ํด ๋์์ต๋๋ค. ๋น๋ก ์ฒ๋ฆฌ ์๋๊ฐ ๋๋ฆฌ์ง๋ง CPU๋ก๋ง ์ด์ฉํ ๊ฒฝ์ฐ์ faster-whisper๊ฐ ์ข์ ์ ํ์ด ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
- ๋์์์์ ์๋ง์ ๋ง๋ค ์ ์๋ stable-ts, whisper ๋๋ faster-whisper ์ง์
- ๊ตฌ๊ธ ํด๋ผ์ฐ๋ ๋ฒ์ญ(ADC ๋๋ API KEY), ๋ค์ด๋ฒ ํํ๊ณ ๋ฒ์ญ(์๋น์ค์ข ๋ฃ), DeepL ๋ฐ DeepL ๋ฒ์ญ ์๋น์ค ์ง์
- ์๋ฏธ ์๋ ์งง์ ์๋ง์ด๋ ๋ฐ๋ณต๋๋ ์๋ง ์ ๊ฑฐ ์ง์
- ์์ฑ ์ธ์์ด ์์ ํ์ง ์์์ ๋๋ฝ๋๋ ์์ฑ์ด๋ ์๋ชป ์ธ์๋ ์ ์์ต๋๋ค. ํ๋กํ์ ๋ํ ์ฉ๋๋ก ์ฌ์ฉ์ ๊ถ์ฅํ์ง ์์ต๋๋ค.
- stable-ts์ whisper ๋ช ๋ น์ด๋ก ํ์ ๋์ ์ด ํ๋ก๊ทธ๋จ์ ์ฌ์ฉํ์ ๋, Whisper WebUI๋ฅผ ์ผ์ ๋ ๊ฐ๊ฐ ์๋ง์ ํ์ง์ด๋ ๊ฐ์๊ฐ ๋ค๋ฅผ ์ ์์ต๋๋ค(์ฐธ๊ณ ๋ก stable-ts๋ ์๋ง ์ถ์ถ ์ฉ๋๋ก ์ต์ ํํ ํ๋ก๊ทธ๋จ์ด๊ธฐ๋ ํ์ง๋ง Whisper ์ค๋ฆฌ์ง๋์ ๋นํด ์ธ์ ๋๋ฝ์ด ์๋ ํธ์ ๋๋ค. ํ์ง๋ง, ์๋๋ฐ ์ถ์ถ๋ ๊ท์ ์๋ฆฌ, ๋ฌด์๋ฏธํ ๋ฐ๋ณต, ๋ท๋ถ๋ถ ์ถ์ถ ์๋๋ ๋ฑ์ ๋ฌธ์ ๋ ์ ์ ํธ์ ๋๋ค.)
- ์ ๋ฃ๋ก ๋ฒ์ญ API๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ฌ์ ์ ๋ณธ ์คํฌ๋ฆฝํธ๋ฅผ ์ถฉ๋ถํ ํ ์คํธํ ํ ๋ฌธ์ ๊ฐ ์์ ๋ ์ด์ฉ ํ์๊ธฐ ๋ฐ๋๋๋ค. ์ ์ฌ์ ์ธ ๋ฒ๊ทธ๋ ์ ์ ์๋ ์ด์ ๋ก ์๊ธธ ์ ์๋ ํผํด์ ๋ํด ์ฑ ์์ง์ง ์์ต๋๋ค.
- stable-ts : GitHub - jianfch/stable-ts: ASR with reliable word-level timestamps using OpenAI's Whisper(https://github.com/jianfch/stable-ts)
- Whisper : General-purpose speech recognition model(https://github.com/openai/whisper)
- faster-whisper : reimplementation of whisper using CTranslate2(https://github.com/guillaumekln/faster-whisper)
์ด ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๋ ค๋ฉด ๋ช ๊ฐ์ง ์ ์ ์กฐ๊ฑด์ ์ค๋นํด์ผ ํฉ๋๋ค(์๋ ์น์ ์ฐธ์กฐ - [์๋์ฐ10/11 ๊ธฐ์ค ์ค๋น ์์ ]).
์๋๋ ์ ์ฒด ์ฌ์ฉ๋ฒ์ ๋ณด๊ธฐ ์ํด -h๋ฅผ ์คํํ ๋ชจ์ต์ ๋๋ค.
usage: subtitle-xtranslator.py [-h] [--framework FRAMEWORK] [--model MODEL] [--device DEVICE]
[--audio_language AUDIO_LANGUAGE] [--subtitle_language SUBTITLE_LANGUAGE]
[--skip_textlength SKIP_TEXTLENGTH] [--translator TRANSLATOR]
[--text_split_size TEXT_SPLIT_SIZE]
audio [audio ...]
positional arguments:
audio audio/video file(s) to transcribe
options:
-h, --help show this help message and exit
--framework FRAMEWORK
name of the stable-ts, whisper or faster-whisper framework to use (default: stable-ts)
--model MODEL tiny, base, small, medium, large-v2, large-v3 model to use (default: medium)
--device DEVICE device to use for PyTorch inference (default: cuda)
--audio_language AUDIO_LANGUAGE
language spoken in the audio, specify None to perform language detection (default: ja)
--subtitle_language SUBTITLE_LANGUAGE
subtitle target language (default: ko)
--skip_textlength SKIP_TEXTLENGTH
skip short text in the subtitles, useful for removing meaningless words (default: 1)
--translator TRANSLATOR
none, google, papago, deepl-api(default: none)
--text_split_size TEXT_SPLIT_SIZE
split the text into small lists to speed up the translation process (default: 1000)
--condition_on_previous_text
if True, provide the previous output of the model as a prompt for the next window; disabling
may make the text inconsistent across windows, but the model becomes less prone to getting
stuck in a failure loop (default: False)
--demucs stable-ts only, whether to reprocess the audio track with Demucs to isolate vocals/remove
noise; pip install demucs PySoundFile; Demucs official repo:
https://github.com/facebookresearch/demucs (default: False)
--vad stable-ts only, whether to use Silero VAD to generate timestamp suppression mask; pip install
silero; Official repo: https://github.com/snakers4/silero-vad (default: False)
--mel_first stable-ts only, process entire audio track into log-Mel spectrogram first instead in chunksif
audio is not transcribing properly compared to whisper, at the cost of more memory usage for
long audio tracks (default: False)
์๋ ๋ช ๋ น์ ๊ฐ ์ธ์๋ค์ ๊ธฐ๋ณธ ๊ฐ์ ๋ช ์์ ์ผ๋ก ํ์ํ์ฌ ์คํํด ๋ณธ ๊ฒ์ ๋๋ค. ์ผ์ด๋ก ๋ ์์์์ ์ถ์ถํ ๊ฒฝ์ฐ์ ๋๋ค.
(venv) C:\Users\loginid> python .\subtitle-xtranslator.py --framework=stable-ts --model=medium --device=cuda --audio_language=ja --skip_textlength=1 '.\inputvideo1.mp4' '.\inputvideo2.mp4' '.\inputvideo3.mp4'
์ค์ ๋ก ์ ๋ช ๋ น์ ๊ธฐ๋ณธ๊ฐ์ ๊ทธ๋๋ก ์ด ๊ฒ์ด๋ผ์ ์ธ์(์๊ท๋จผํธ)๋ฅผ ์๋ตํด๋ ๋ฉ๋๋ค. ๋ค๋ง --translator์ ๊ธฐ๋ณธ์ none์ด๋ผ์ ๋ฒ์ญ์ ํ์ง ์๊ณ ์๋ง ์ถ์ถ๋ง ํ๊ฒ ๋ฉ๋๋ค.
(venv) C:\Users\loginid> python .\subtitle-xtranslator.py '.\inputvideo1.mp4' '.\inputvideo2.mp4' '.\inputvideo3.mp4'
๋ฌผ๋ก ์ถ์ถ๋ ์๋ง์ ํ๊ตญ์ด๋ก ์๋ ๋ฒ์ญ์ ํ๊ธฐ ์ํด์๋ --translator google๋ --translator deepl-api ์ค ํ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
๋ฒ์ญ๊ธฐ๋ฅผ ์ด์ฉํ๊ธฐ ์ํ์ฌ API ํค๋ฅผ ์ ๊ณตํ๋ ค๋ฉด ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉ ํฉ๋๋ค.
Google์ ๊ฒฝ์ฐ ADC(์ ํ๋ฆฌ์ผ์ด์ ๊ธฐ๋ณธ ์๊ฒฉ ์ฆ๋ช - ํน์ ํ์ผ ์์ฑ) ๋๋ API ํค๋ฅผ ์ ํํ ์ ์์ผ๋ฉฐ, ๋ค์์ API ํค์ ๋ํ ์ค๋ช ์ ๋๋ค. ADC๋ ๋ก์ปฌ ์ปดํจํฐ์ ํด๋ผ์ฐ๋ ์ฌ์ฉ์ ์ํ ์ธ์ฆ ํ์ผ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ด๋ผ์ API ํค ์ ์ถ์ ๊ฑฑ์ ํ ํ์๊ฐ ์์ต๋๋ค. ๋ฌผ๋ก ํด๋น ํ์ผ์ด ์ ์ถ๋๋ฉด ์๋๊ฒ ์ง์... ๋ค์ ๋ฒ๊ฑฐ๋กญ์ง๋ง ์์ค์ฝ๋์ API ํค๋ฅผ ๋ด์ฅํ๋ ๊ฒ๋ณด๋ค๋ ์๋์ ๊ฐ์ด ํ๊ฒฝ ๋ณ์๋ก ์ง์ ํด ์ฃผ๋ ๊ฒ์ด ๋ณด์์ ๋ ์ข์ ๋ณด์ ๋๋ค. ๋ค๋ง, ํด๋น ์ธ์ ์์๋ง ์๋ํ๋ฏ๋ก ์ปดํจํฐ๋ฅผ ๊ป๋ค ์ผ๊ฑฐ๋ ํ์์๊ณผ venv๋ฅผ ๋ค์ ๋ก๋ฉํ๋ค๋ฉด ๋ ํด์ฃผ์ด์ผ ํ๋ ๋ฒ๊ฑฐ๋ก์์ ์์ต๋๋ค.
๊ตฌ๊ธ ํด๋ผ์ฐ๋ ๋ฒ์ญ์ ์ด์ฉํ๋ ค๋ฉด ๊ตฌ๊ธ ํด๋ผ์ฐ๋ ์ฝ์์์ ํ๋ก์ ํธ๋ฅผ ์๋ก ํ๋ ๋ง๋ค๊ณ Google Cloud Translation์๋น์ค๋ฅผ ์ ํํ๊ณ ADC๋ฅผ ์ค์ ํ๊ฑฐ๋ API key๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค. ADC๋ง๊ณ API key๋ง ๋ฐ๋ ๋ฐฉ๋ฒ์ ์ข ๋ ๊ฐ๋จํด ๋ณด์ ๋๋ค(https://urame.tistory.com/entry/GoogleGCP-Translation-API%EB%B2%88%EC%97%AD-API-%EC%8B%A0%EC%B2%AD-%EB%B0%8F-PYTHON-%ED%85%8C%EC%8A%A4%ED%8A%B8).
- https://console.cloud.google.com/
- https://cloud.google.com/translate/docs/basic/translating-text
- https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=ko#local-dev
๋น์ฉ : ์๊ธ์ Cloud Translation์ ์ ๊ณต๋ ๋ฌธ์ ์๋ก ์กฐ์ ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด ํ ๋ฌ์ 575,000์๋ฅผ ์ ์กํ์ฌ ์ฒ๋ฆฌํ ๊ฒฝ์ฐ $1.50๊ฐ ์ฒญ๊ตฌ๋ฉ๋๋ค. ์ฒ์ 500,000์๋ ๋ฌด๋ฃ์ด๊ณ ๋ค์ 75,000์๋ $20๋ฌ๋ฌ/100๋ง์(์๋ฌธ ๊ธฐ์ค) ์์จ๋ก ์ฒญ๊ตฌ๋ฉ๋๋ค. 7.5๋ง์ x 0.2๋ฌ๋ฌ/๋ง์ = 1.5๋ฌ๋ฌ
(venv) C:\Users\loginid> Set-Item -Path env:GOOGLE_API_KEY -Value "your_api_key"
DeepL์ ์๋์ ๊ฐ์ด ๊ฐ๋ฐ์ ๋ฑ๋กํ ํ ๋ฐ์ ์ ์๋ APIํค๋ฅผ ํ๊ฒฝ ๋ณ์๋ก ์ ๊ณตํ๋ฉด ๋ฉ๋๋ค. ์ 50๋ง์๊น์ง ๋ฌด๋ฃ๋ก ์ด์ฉ ๊ฐ๋ฅํฉ๋๋ค. ๋ช ๋ น ํ๋กฌํํธ์์๋ set DEEPL_API_KEY=your_api_key ์ ๊ฐ์ด ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ ์ ์์ต๋๋ค.
(venv) C:\Users\loginid> Set-Item -Path env:DEEPL_API_KEY -Value "your_api_key"
DeepL API ๋ฒ์ญ์ ์ด์ฉํ๋ ค๋ฉด ์ต์ด 1ํ ๊ด๋ จ ํจํค์ง๋ฅผ ์ค์นํด ์ฃผ์ด์ผ ํฉ๋๋ค.
(venv) C:\Users\loginid> pip install --upgrade deepl
(venv) C:\Users\loginid> Set-Item -Path env:DEEPL_API_KEY -Value "your_api_key"
๊ทธ๋ฌ๋ฉด ์๋ฅผ ๋ค์ด ๋ณด๊ฒ ์ต๋๋ค. --translator๋ก๋ deepl-api๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ถ ๋ฐฉ๋ฒ์ stable-ts๋ฅผ ์ ํํ๋๋ฐ, stable-ts์ demucs=True, vad=True, mel_first=True ์ต์ ์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ์ด๋ ๊ฒ ํ๋ฉด ๋ฉ๋๋ค. ์์ด๋ก ๋์ด ์๋ ๋์์์ ๋๋ค.
(venv) C:\Users\loginid> Set-Item -Path env:DEEPL_API_KEY -Value "your_api_key"
(venv) C:\Users\loginid> python .\subtitle-xtranslator.py --demucs --vad --mel_first --audio_language en --translator deepl-api --text_split_size 3000 'Y:\video_cut.mp4'
demucs, vad, mel_first์ ๊ดํ์ฌ๋ stable-ts์ ๊ฐ๋ฐ์ ํ์์๋ ๋ค์๊ณผ ๊ฐ์ ์ด์ผ๊ธฐ๊ฐ ์์ต๋๋ค.
- ์์ ์๋ demucs=True, vad=True๋ฅผ ์ฌ์ฉํ์ง๋ง ์์ ์ด ์๋ ๊ฒฝ์ฐ์๋ ์๋ํฉ๋๋ค.
- ์ค๋์ค๊ฐ Whisper์ ๋นํด ์ ๋๋ก ์ถ์ถ๋์ง ์๋ ๊ฒฝ์ฐ, ๊ธด ์ค๋์ค ํธ๋์ ๊ฒฝ์ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ๋์ด๋์ง๋ง mel_first=True๋ฅผ ์ฌ์ฉํด ๋ณด์ธ์.
demucs์ vad๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋ค์ ํจํค์ง๋ค๋ ์ค์นํ์ฌ์ผ ํฉ๋๋ค.
(venv) C:\Users\loginid> pip install wheel
(venv) C:\Users\loginid> pip install demucs PySoundFile
(venv) C:\Users\loginid> pip install silero
๋ง์ฝ ์ค์น ์ค ์ค๋ฅ๊ฐ ๋๋ฉด https://visualstudio.microsoft.com/ko/visual-cpp-build-tools/ ๋ฅผ ์ค์นํ ํ์๊ฐ ์์ต๋๋ค.
๋ค๋ง, demucs์ ๊ฒฝ์ฐ ๋์์์ด ๊ธด ๊ฒฝ์ฐ GPU๋ฉ๋ชจ๋ฆฌ ๋ง์ด ์ฌ์ฉํ๋ฉฐ, 8GB VRAM์์๋ ์ ๋ ์ ์๊ณ (์: 2์๊ฐ40๋ถ MP4๊ฐ 13GB VRAM์ ์๊ตฌ), ์ถ๊ฐ ์ฒ๋ฆฌ ์๊ฐ(6~7๋ถ)์ ํ์๋ก ํฉ๋๋ค. vad๋ ๋ง์ฐฌ๊ฐ์ง๋ก ๋์์์ ์ฒ์๋ถํฐ ๋๊น์ง ํ์ํ๋ฏ๋ก ์ค๋ ๊ฑธ๋ฆฝ๋๋ค.
์ค์ stable-ts์ deepl-api๋ฅผ ์ด์ฉํ์ฌ ์ถ์ถ๊ณผ ๋ฒ์ญ์ ํ๋ ๋ชจ์ต์ ๋์์์ผ๋ก ๋ด์์ต๋๋ค. https://www.youtube.com/watch?v=Orq6CGHw8Ag
ํ์ด์ฌ์ ์ต์ ๋ฒ์ ์ ์ค์น๋ฅผ ํฉ๋๋ค. ์๋์ฐ11์ ๋ช ๋ น ํ๋กฌํํธ๋ ํ์์ ์๋ฌด๋ฐ์๋ python์ด๋ผ๊ณ ์น๋ฉด ์คํ๋ ์ ์๋๋ก ํ๋ ๊ฒ์ด ๋ชฉํ์ ๋๋ค.
https://www.python.org/downloads https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe
NVIDIA ๋น๋์ค ์นด๋์ ์ฑ๋ฅ์ ํ์ฉํ๊ธฐ ์ํด ์ค์นํฉ๋๋ค.
์ค์น ์๋ฃ ํ cuda๊ฐ ์ ๋๋ก ์ค์น๋์ด ์๋ ์ง ํ์ธํ๋ ค๋ฉด ํ์์(Windows PowerShell ์ฑ)์ ๋์ฐ๊ณ , nvidia-smi ๋ผ๊ณ ๋ช ๋ น์ ๋ด๋ ค ๋ณด๋ฉด ์ ์ ์์ต๋๋ค.
https://developer.nvidia.com/cuda-toolkit https://developer.download.nvidia.com/compute/cuda/12.2.1/local_installers/cuda_12.2.1_536.67_windows.exe
๋ง์ฝ faster-whisper๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด cuDNN์ ์ค์น๊ฐ ํ์์ ๋๋ค. cuDNN์ https://developer.nvidia.com/cudnn-downloads ์์ ๋ฐ์ ์ ์์ต๋๋ค. https://developer.download.nvidia.com/compute/cudnn/9.6.0/local_installers/cudnn_9.6.0_windows.exe ๋ฅผ ๋ฐ์์ ์ค์นํฉ๋๋ค. ๊ธฐ๋ณธ ์ค์ ๋๋ก ์ค์นํ๋ฉด C:\Program Files\NVIDIA\CUDNN\v9.6\bin ์ dllํ์ผ์ด ์๊น๋๋ค. ์ด ํ์ผ๋ค์ C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin ๋ฐ์ผ๋ก ๋ณต์ฌํด ์ฃผ์ธ์.
faster-whisper๋ฅผ ์ํด ์ ํ์ ์ผ๋ก ์ค์นํ๋ cuBLAS๋ ์๋์ venv ํ๊ฒฝ์ด ๋ง๋ค์ด์ง ํ pip install nvidia-cublas-cu12 ๋ช ๋ น์ ํตํด ์ค์นํ ์ ์์ต๋๋ค.
์๋์ฐํค๋ฅผ ๋๋ฅด๊ณ Rํค๋ฅผ ๋๋ฅด๋ฉด ์ข์ธก์ ์คํ ์ฐฝ์ด ๋ํ๋ฉ๋๋ค. ์ด๊ณณ์ "powershell"์ ์ ๋ ฅํ๊ณ ํ์ธ์ ๋๋ฅด๋ฉด ํ์์์ ์คํํ ์ ์์ต๋๋ค(์ด์ธ์ ๋ค์ํ ๋ฐฉ๋ฒ์ผ๋ก ์คํ ๊ฐ๋ฅ).
ํ์์ ์ฐฝ์์ python์ด๋ผ๊ณ ์น๊ณ [Enter]ํค๋ฅผ ๋๋ฅด๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์๋ต์ด ๋์์ผ ํฉ๋๋ค.
PS C:\Users\login_id> python
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
์ >>> ์์ ๋์ค๊ธฐ ์ํด์๋ exit() ์ ์ ๋ ฅํฉ๋๋ค.
ํ์ด์ฌ์ ํจํค์ง๋ฅผ ํ์ํ ๋๋ง๋ค ์ค์นํ๊ฒ ๋๋๋ฐ, ์์คํ ์ ์ค์น๋ ํ์ด์ฌ์ ๊ทธ๋ฅ ์ค์นํ๋ค๋ณด๋ฉด ๊ฐ๋ ๋ญ๊ฐ๊ฐ ๊ผฌ์ด๊ฒ ๋๊ณ ๋ฌธ์ ๊ฐ ๊ฐ๋ ์๊ธฐ๋๋ฐ ์์ฃผ ๋จธ๋ฆฌ๊ฐ ์ํ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฌผ๋ก , ์ด ๊ธฐ๋ฅ๋ง ์ด์ฉํ๊ฒ ๋คํ๋ฉด ์๊ด์์ง๋ง ๊ทธ๋๋ ์ ๊ฑฐ๊ฐ ํธํ๋๋ก ๊ฐ์์ ํ๊ฒฝ์ ๋ง๋ค์ด ์ค๋๋ค.
์๋๋ ์ฌ์ฉ์ ๋๋ ํฐ๋ฆฌ์ ๊ทธ๋ฅ ์ค์นํ๋๋ฐ ๋ค๋ฅธ ๋๋ผ์ด๋ธ๋ ํด๋์ ํด๋ ๋ฉ๋๋ค(์ฃผ์: ๊ฒฝ๋ก ์์ ํ๊ธ์ด ์๋ ๊ณณ์์ ์์ ํด์ฃผ์ธ์. ํน์ ์๋์ฐ ๋ก๊ทธ์ธ๋ช ์ด ํ๊ธ์ด๋ผ๋ฉด ๋ค๋ฅธ ๊ณณ์ ์ค์น๊ฐ ํ์ํฉ๋๋ค.)
์ฉ๋์ด 4.5GB๊ฐ๋ ๋๋ฏ๋ก ์ ์ ํ ๋์คํฌ ๋๋ผ์ด๋ธ์ ์ค์นํ์๋ฉด ์ข์ต๋๋ค.
(์ฃผ์: ๊ฒฝ๋ก์์ ํ๊ธ์ด ํฌํจ๋๋ฉด ์๋ฉ๋๋ค.)
PS C:\Users\login_id> python -m venv venv
PS C:\Users\login_id> .\venv\Scripts\Activate.ps1
๋ง์ฝ .ps1๊ฐ ์คํ์ด ์๋๋ฉด ํ์์์ ๊ด๋ฆฌ์ ๊ถํ์ผ๋ก ์คํํ ํ, ์๋ ๋ช ๋ น์ ํ๋ฒ ์คํํด ์ค๋๋ค.
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
์์ ๊ฐ์ด ํด์ฃผ๋ฉด, ๊ฐ์ ํ๊ฒฝ ์ค๋น๊ฐ ๋๋ฉ๋๋ค. ์ฒ์์ ์คํํ ๋ ๋ณด์ ๊ด๋ จ ๋ฌธ์๊ฐ ๋์ค๋๋ฐ Always๋ฅผ ์ ํํด ์ค๋๋ค. venv๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์คํ๋๋ฉด ํ๋กฌํํธ๊ฐ ๋ฐ๋๋๋ค.
GPU๋ฒ์ ์ ํ ์น๋ฅผ ์ค์นํฉ๋๋ค(๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ์ผ๋ก ์ค์น ์คํจ ์ --no-cache-dir ์ถ๊ฐ).
(venv) PS C:\Users\login_id> pip install torch==2.2.1+cu121 --extra-index-url https://download.pytorch.org/whl/cu121
์ ์ค์น๊ฐ ๋์๋ ์ง ํ์ธํ๊ธฐ ์ํด python์ ์ ๋ ฅํ๊ณ ๊ฐ๋จํ ํ๋ก๊ทธ๋จ์ ์งญ๋๋ค. (์ฃผ์) "version" ์ ๊ธ์์ ์ข์ฐ์ ์ธ๋๋ฐ๊ฐ 2๊ฐ์ฉ ์์ต๋๋ค.
(venv) PS C:\Users\login_id> python
Python 3.11.4 [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.2.1+cu121
>>> exit()
์ ๊ณผ์ ์์ ์๋์ ๊ฐ์ ์ค๋ฅ๊ฐ ๋๋ค๋ฉด, https://aka.ms/vs/16/release/vc_redist.x64.exe ๋ฅผ ์ถ๊ฐ๋ก ์ค์นํ ํ ์ฌ์๋๋ฅผ ํ์ฌ ๋ด ๋๋ค.
(venv) PS C:\Users\login_id> python
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.
It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\login_id\venv\Lib\site-packages\torch\__init__.py", line 133, in <module>
raise err
OSError: [WinError 126] ์ง์ ๋ ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค. Error loading "C:\Users\login_id\venv\Lib\site-packages\torch\lib\c10.dll" or one of its dependencies.
์ด ์ํ์์ ํฅํ ํ์ํ ํจํค์ง๋ค์ ์ค์นํฉ๋๋ค.
(venv) PS C:\Users\login_id> pip install -U openai-whisper
(venv) PS C:\Users\login_id> pip install -U stable-ts
(venv) PS C:\Users\login_id> pip install -U google-cloud-translate
ํน์ ๊ฐ์ด ์ฒจ๋ถ๋ requirements.txt๋ฅผ ์ด์ฉํ ์๋ ์์ต๋๋ค.
(venv) PS C:\Users\login_id> pip install -r requirements.txt
์ฐธ๊ณ ๋ก, ๊ทธ๋์ ํ ์คํธํ ๋ stable-ts๋ ์ฃผ๋ก 2.6.2๋ฅผ ์ฌ์ฉ ํ์๋๋ฐ, ๊ณ์ ์ ๊ทธ๋ ์ด๋๊ฐ ์ด๋ฃจ์ด์ง๊ณ ์์ผ๋ฏ๋ก ์ต์ ๋ฒ์ ์ ์ค์นํ๊ณ ๊ฒฐ๊ณผ๊ฐ ๋ง์กฑ์ค๋ฝ์ง ์์ ๋์ ํน์ ๋ฒ์ ์ผ๋ก ๋ฐ๊พธ์ด ์ค์นํ๋ ๋ฐฉ๋ฒ๋ ๊ณ ๋ คํด ๋ณผ ์ ์์ต๋๋ค.
pip install stable-ts==2.6.2
๋ง์ฝ faster-whisper๋ฅผ ์ฌ์ฉํ ์์ ์ด๋ผ๋ฉด, ์๋ ๋ช ๋ น์ ์ถ๊ฐ๋ก ์งํํด ์ค๋๋ค. int8๋ก ๊ณ ์ ๋์ด ์์ผ๋ฏ๋ก subtitle-xtranslator.py์ 518๋ฒ์งธ ์ค์ ์ฝ๋ model = WhisperModel(model_name, device=device, compute_type="int8") ์ int8๋ก ๋์ด ์๋ ๋ถ๋ถ์ fp16 ๋ฑ์ผ๋ก ์์ ํ์ฌ ์ด์ฉํ ์ ์์ต๋๋ค.
pip install nvidia-cublas-cu12
pip install faster-whisper
์์์์ ์์ฑ์ ์ถ์ถ์ ํ๋ค๋ณด๋ ์ธ๋ถ ํ๋ก๊ทธ๋จ์ด ํ๋ ํ์ํฉ๋๋ค.
https://www.gyan.dev/ffmpeg/builds/#release-builds ์์ ffmpeg-release-essentials.zip ์ ๋ฐ์์ ์์ถ ํด์ ํ ํ, ์์ผ๋ก ์์ ํ ๋๋ ํฐ๋ฆฌ๋ ํ๊ฒฝ๋ณ์์์ Path๊ฐ ์ค์ ๋์ด ์๋ ๊ณณ์ ๋ณต์ฌํ์ฌ๋ ๋ฉ๋๋ค. ๊ทธ๋ฅ C:\Users\login_id\venv\Scripts ๋ฐ์ ๋ณต์ฌํ๋ ๊ฒ์ด ์ํธํ๊ฒ ์ต๋๋ค.
์งง์ ์์ ํ๋๋ฅผ ํ ์คํธํ๋ ๊ณผ์ ์ ๋ณด์ฌ๋๋ฆฝ๋๋ค(์ค์ ๋ก๋ ์ค๊ฐ์ warning์ด ๋์ค์ง๋ง ์๋์ ๋ฌธ์ ๋ ์์ต๋๋ค).
(venv) PS C:\Users\login_id> python
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import stable_whisper
>>> model = stable_whisper.load_model("small", device="cuda")
>>> result = model.transcribe(verbose=True, word_timestamps=False, language="ko", audio="20220902_131203.mp4")
[00:12.800 --> 00:16.080] ์ ์๊น ๋ฑ ์ฐ์์ด์ผ ๋๋๋ฐ
[00:19.580 --> 00:21.580] ๋ถํ๋์ ์น๋ ๊ฑธ ์ฐ์์ด์ผ ๋๋๋ฐ
[00:30.000 --> 00:34.980] ์ง์ถํ๋๊ฒ ์ง
>>> result.to_srt_vtt("20220902_131203.srt")
Saved: C:\Users\login_id\20220902_131203.srt
>>> exit()
word_timestamps=True๊ฐ ๊ธฐ๋ณธ ๊ฐ์ธ๋ฐ, ๋งํ๋ ์ค ๋จ์ด๊ฐ ํ์ด๋ผ์ดํธ ๋๋ ๊ธฐ๋ฅ์ด ์์ต๋๋ค. 2GB์ VRAM์ ๊ฐ์ง ๊ทธ๋ํฝ์นด๋๋ผ์ small ๋ชจ๋ธ๋ก ํ๋๋ฐ, ๋ช ๋ง๋(๋ถํ๋->์คํ๋, ์ง์ถํ๋๊ฒ ์ง๋ ๊ทธ๋ฅ ํ๋ ์๋ฆฌ๊ฐ ์๋งํ ๋์๋ค์)๋ ์๋ชป ์ธ์ํ๋ค์. 8GB VRAM์ด๋ผ๋ฉด medium์ผ๋ก ํ๋ฉด ๋ฉ๋๋ค.
๋ง์ฝ git๋ฅผ ์ค์นํด ๋์๋ค๋ฉด ์๋์ ๊ฐ์ด ๋ฐ์ผ๋ฉด ๋ฉ๋๋ค. ๊ทธ๋ ์ง ์๋ค๋ฉด https://github.com/sevengivings/subtitle-xtranslator ์ ์ ์ํด์ ์ฐ์ธก์ "<> CODE"๋ผ๋ ๋ช ๋ น๋ฒํผ์ด ๋ณด์ ๋๋ค. ๋ฒํผ์ ๋๋ฅด๋ฉด Download ZIP ๋ฉ๋ด๋ฅผ ํตํด ์์ถ ํ์ผ๋ก ๋ฐ์ ์ ์๊ณ , ์ ๋นํ ๊ณณ์ ์์ถ ํด์ ํ ํ ์ด์ฉํ ์ ์์ต๋๋ค.
(venv) C:\Users\login_id> git clone https://github.com/sevengivings/subtitle-xtranslator
(์ฃผ์) ๋ง์ฝ ํ๊ธ๋ก ๋ ์๋ด ๋ฉ์์ง๋ฅผ ๋ณด๋ ค๋ฉด ์์ถ ํ์ผ์ locale ๋๋ ํ ๋ฆฌ๋ ํ์ํฉ๋๋ค.
์ง๊ธ๊น์ง๋ python .\subtitle-xtranslator.py๋ก ์คํ์ ํ์ต๋๋ค. ๋ค์ ๋ถํธํ๋ฏ๋ก exeํ์ผ๋ก ๋ง๋ ํ, venv\Scripts์ ๋ณต์ฌํ์ฌ ์๋ฌด ๋๋ผ์ด๋ธ๋ ๋๋ ํ ๋ฆฌ์์๋ ์คํํ ์ ์๋๋ก ํด๋ณด๊ฒ ์ต๋๋ค.
(venv) C:\Users\login_id> pip install pyinstaller
(venv) C:\Users\login_id> pyinstaller --onefile .\subtitle-xtranslator.py
์ ๊ฒฐ๊ณผ๋ก ๋์ค๋ C:\Users\login_id\dist\subtitle-xtranslator.exe๋ฅผ ์๋์ฐ์ ๊ฒฝ๋ก PATH๊ฐ ์ง์ ๋ ์๋ฌด ๊ณณ์๋ ๋ณต์ฌํ๋ฉด ๋ฉ๋๋ค. ์ด์ ์ด๋ ๊ณณ์์๋ ์คํ์ด ๊ฐ๋ฅํด์ง๋๋ค(venv์ ๊ด๊ณ ์์ด).
์ ๋ฐฉ์์ผ๋ก ๋ง๋ค๋ฉด ์ฝ 2.7GB์ ํฌ๊ธฐ๋ฅผ ๊ฐ์ง๊ณ ์์ด์ ๋ง๋๋๋ฐ, ๊ทธ๋ฆฌ๊ณ ์คํํ ๋ ์ค๋(1~2๋ถ) ๊ฑธ๋ฆฌ๊ธฐ๋ ํ๊ณ ์ค์ฉ์ ์ด์ง๋ ๋ชปํด ๋ณด์ ๋๋ค.
