{ "cells": [ { "cell_type": "markdown", "id": "8a946fce-7e0d-46cb-a053-d78dc31fb121", "metadata": {}, "source": [ "## Coversion" ] }, { "cell_type": "code", "execution_count": null, "id": "3c01a6d9-6569-4c94-b2a4-39696c423b1f", "metadata": { "scrolled": true }, "outputs": [], "source": [ "!pip install ctranslate2 transformers hf-transfer" ] }, { "cell_type": "code", "execution_count": null, "id": "3fd0bbb0-6496-4465-87a5-8827c1a5ed47", "metadata": { "scrolled": true }, "outputs": [], "source": [ "!ct2-transformers-converter \\\n", " --model SadeghK/whisper-large-v3-turbo \\\n", " --output_dir whisper-large-v3-turbo-ct2 \\\n", " --copy_files tokenizer.json preprocessor_config.json \\\n", " --quantization float16" ] }, { "cell_type": "code", "execution_count": 57, "id": "b9a52b37-21d2-4758-a18f-7d59fec6fd43", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mWARNING: Skipping whisperx as it is not installed.\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip uninstall -y whisperx\n", "!rm -rf /usr/local/lib/python3.12/dist-packages/whisperx\n", "!rm -rf /usr/local/lib/python3.12/dist-packages/whisperx-*" ] }, { "cell_type": "code", "execution_count": 58, "id": "ac12e621-eec9-43b2-8186-2afc382b0ec1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "import importlib\n", "import sys\n", "print(\"whisperx\" in sys.modules)" ] }, { "cell_type": "code", "execution_count": null, "id": "a0f1e4c6-1b20-4ff7-9fd6-9bb16414cceb", "metadata": {}, "outputs": [], "source": [ "!pip install whisperx\n", "# !pip install git+https://github.com/m-bain/whisperx.git" ] }, { "cell_type": "code", "execution_count": 10, "id": "2a98f8a1-dee5-4582-b74e-fb6e93815152", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2025-12-08 20:09:34 - whisperx.asr - INFO - No language specified, language will be detected for each audio file (increases inference time)\n", "2025-12-08 20:09:34 - whisperx.vads.silero - INFO - Performing voice activity detection using Silero...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Using cache found in /root/.cache/torch/hub/snakers4_silero-vad_master\n" ] } ], "source": [ "import whisperx\n", "device = \"cuda\"\n", "\n", "asr = whisperx.load_model(\n", " \"whisper-large-v3-turbo-ct2\",\n", " device=\"cuda\",\n", " compute_type=\"float16\",\n", " vad_method=\"silero\"\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "05764e18-df38-46d2-ae09-fbfda0a5d402", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2025-12-08 20:10:06 - whisperx.asr - WARNING - Audio is shorter than 30s, language detection may be inaccurate\n", "2025-12-08 20:10:06 - whisperx.asr - INFO - Detected language: fa (1.00) in first 30s of audio\n", "{'segments': [{'text': 'علت اصلی بارش باران جابجایی هوای مفتوب به علت اختلاف دما و رطوبت است که به جبههه\\u200cهای هوا شناسی معروف است', 'start': 0.066, 'end': 10.174}], 'language': 'fa'}\n" ] } ], "source": [ "result = asr.transcribe(\"test.wav\")\n", "print(result)" ] }, { "cell_type": "code", "execution_count": 14, "id": "a94da22c-35a8-4e72-9897-1634e9f77998", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2b3e88bc25464c7b8efe3646fea7845a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "preprocessor_config.json: 0%| | 0.00/158 [00:00\"" ] }, { "cell_type": "code", "execution_count": null, "id": "6e041a99-a97f-4fcb-9a98-4d2e07991f42", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# !apt-get update && apt-get install tree" ] }, { "cell_type": "code", "execution_count": 27, "id": "a15ad6d5-1db1-4ba7-8575-01099aaecaba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[01;34m.\u001b[0m\n", "├── \u001b[01;35mtest.wav\u001b[0m\n", "├── \u001b[01;34mwhisper-large-v3-turbo-ct2\u001b[0m\n", "│   ├── \u001b[00mconfig.json\u001b[0m\n", "│   ├── \u001b[00mmodel.bin\u001b[0m\n", "│   ├── \u001b[00mpreprocessor_config.json\u001b[0m\n", "│   ├── \u001b[00mtokenizer.json\u001b[0m\n", "│   └── \u001b[00mvocabulary.json\u001b[0m\n", "└── \u001b[00mwhisper-v3-turbo-to-whisperx-pipeline.ipynb\u001b[0m\n", "\n", "2 directories, 7 files\n" ] } ], "source": [ "!tree -L 2" ] }, { "cell_type": "code", "execution_count": 28, "id": "d1a87396-b606-4393-9491-d11c13587be5", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import HfApi\n", "\n", "api = HfApi()" ] }, { "cell_type": "code", "execution_count": 30, "id": "a3a69f73-90e3-427c-83fd-07409fe87dac", "metadata": { "scrolled": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c187855215aa4a1aa1b3a0721d7cc43a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Processing Files (0 / 0): | | 0.00B / 0.00B " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c956c4df8e984234be287a31d14b1986", "version_major": 2, "version_minor": 0 }, "text/plain": [ "New Data Upload: | | 0.00B / 0.00B " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/SadeghK/whisper-large-v3-turbo-ct2/commit/d69b61686833e10061aa5805f2d7ec33c6cf154c', commit_message='Upload folder using huggingface_hub', commit_description='', oid='d69b61686833e10061aa5805f2d7ec33c6cf154c', pr_url=None, repo_url=RepoUrl('https://huggingface.co/SadeghK/whisper-large-v3-turbo-ct2', endpoint='https://huggingface.co', repo_type='model', repo_id='SadeghK/whisper-large-v3-turbo-ct2'), pr_revision=None, pr_num=None)" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.upload_folder(\n", " folder_path=\"whisper-large-v3-turbo-ct2\",\n", " path_in_repo=\".\",\n", " repo_id=\"SadeghK/whisper-large-v3-turbo-ct2\",\n", " repo_type=\"model\"\n", ")" ] }, { "cell_type": "markdown", "id": "06833856-bc89-4380-bb24-f117656a7829", "metadata": {}, "source": [ "## Inference (with fater-whisper)" ] }, { "cell_type": "code", "execution_count": null, "id": "51bd55ae-4a42-4126-aeca-42ffab481d86", "metadata": { "scrolled": true }, "outputs": [], "source": [ "!pip install faster-whisper" ] }, { "cell_type": "code", "execution_count": 33, "id": "dea2c1c8-eff2-4a21-836a-97b23eae85ec", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f4140822bc7542c09ad624b4d624fee0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "config.json: 0.00B [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3bfef789f4044b189383714c87137d03", "version_major": 2, "version_minor": 0 }, "text/plain": [ "model.bin: 0%| | 0.00/1.62G [00:00