{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": { "id": "-b_6DpRU-uqm" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: typing-extensions in c:\\users\\user\\anaconda3\\lib\\site-packages (4.8.0)\n" ] } ], "source": [ "!pip install --upgrade typing-extensions" ] }, { "cell_type": "markdown", "metadata": { "id": "zAi-ZzbbZrjL" }, "source": [ "## **下載whisper套件**" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "id": "fBeLbJPAaire" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: gradio in c:\\users\\user\\anaconda3\\lib\\site-packages (4.3.0)\n", "Requirement already satisfied: aiofiles<24.0,>=22.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (22.1.0)\n", "Requirement already satisfied: altair<6.0,>=4.2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (5.1.2)\n", "Requirement already satisfied: fastapi in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.104.1)\n", "Requirement already satisfied: ffmpy in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.3.1)\n", "Requirement already satisfied: gradio-client==0.7.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.7.0)\n", "Requirement already satisfied: httpx in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.25.1)\n", "Requirement already satisfied: huggingface-hub>=0.14.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.19.1)\n", "Requirement already satisfied: importlib-resources<7.0,>=1.3 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (6.1.1)\n", "Requirement already satisfied: jinja2<4.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (3.1.2)\n", "Requirement already satisfied: markupsafe~=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (2.1.1)\n", "Requirement already satisfied: matplotlib~=3.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (3.7.1)\n", "Requirement already satisfied: numpy~=1.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (1.24.3)\n", "Requirement already satisfied: orjson~=3.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (3.9.10)\n", "Requirement already satisfied: packaging in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (23.0)\n", "Requirement already satisfied: pandas<3.0,>=1.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (1.5.3)\n", "Requirement already satisfied: pillow<11.0,>=8.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (9.4.0)\n", "Requirement already satisfied: pydantic>=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (2.5.0)\n", "Requirement already satisfied: pydub in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.25.1)\n", "Requirement already satisfied: python-multipart in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.0.6)\n", "Requirement already satisfied: pyyaml<7.0,>=5.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (6.0)\n", "Requirement already satisfied: requests~=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (2.31.0)\n", "Requirement already satisfied: semantic-version~=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (2.10.0)\n", "Requirement already satisfied: tomlkit==0.12.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.12.0)\n", "Requirement already satisfied: typer[all]<1.0,>=0.9 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.9.0)\n", "Requirement already satisfied: typing-extensions~=4.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (4.8.0)\n", "Requirement already satisfied: uvicorn>=0.14.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio) (0.24.0.post1)\n", "Requirement already satisfied: fsspec in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio-client==0.7.0->gradio) (2023.10.0)\n", "Requirement already satisfied: websockets<12.0,>=10.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio-client==0.7.0->gradio) (11.0.3)\n", "Requirement already satisfied: jsonschema>=3.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (4.17.3)\n", "Requirement already satisfied: toolz in c:\\users\\user\\anaconda3\\lib\\site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n", "Requirement already satisfied: filelock in c:\\users\\user\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.14.0->gradio) (3.9.0)\n", "Requirement already satisfied: tqdm>=4.42.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.14.0->gradio) (4.65.0)\n", "Requirement already satisfied: contourpy>=1.0.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.0.5)\n", "Requirement already satisfied: cycler>=0.10 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (0.11.0)\n", "Requirement already satisfied: fonttools>=4.22.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (4.25.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (1.4.4)\n", "Requirement already satisfied: pyparsing>=2.3.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (3.0.9)\n", "Requirement already satisfied: python-dateutil>=2.7 in c:\\users\\user\\anaconda3\\lib\\site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from pandas<3.0,>=1.0->gradio) (2022.7)\n", "Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from pydantic>=2.0->gradio) (0.6.0)\n", "Requirement already satisfied: pydantic-core==2.14.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from pydantic>=2.0->gradio) (2.14.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio) (2023.7.22)\n", "Requirement already satisfied: click<9.0.0,>=7.1.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (8.0.4)\n", "Requirement already satisfied: colorama<0.5.0,>=0.4.3 in c:\\users\\user\\anaconda3\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n", "Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n", "Requirement already satisfied: rich<14.0.0,>=10.11.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from typer[all]<1.0,>=0.9->gradio) (13.6.0)\n", "Requirement already satisfied: h11>=0.8 in c:\\users\\user\\anaconda3\\lib\\site-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n", "Requirement already satisfied: anyio<4.0.0,>=3.7.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from fastapi->gradio) (3.7.1)\n", "Requirement already satisfied: starlette<0.28.0,>=0.27.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from fastapi->gradio) (0.27.0)\n", "Requirement already satisfied: httpcore in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpx->gradio) (1.0.2)\n", "Requirement already satisfied: sniffio in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpx->gradio) (1.2.0)\n", "Requirement already satisfied: attrs>=17.4.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (22.1.0)\n", "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.0)\n", "Requirement already satisfied: six>=1.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.2.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.15.1)\n", "Requirement already satisfied: mdurl~=0.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.0)\n" ] } ], "source": [ "!pip install gradio" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "BdhO4TAacxw3", "outputId": "fe28e610-183a-4f34-9074-833a22c4cbbe" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: openai-whisper in c:\\users\\user\\anaconda3\\lib\\site-packages (20231106)\n", "Requirement already satisfied: numba in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (0.57.0)\n", "Requirement already satisfied: numpy in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (1.24.3)\n", "Requirement already satisfied: torch in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (2.0.1+cu118)\n", "Requirement already satisfied: tqdm in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (4.65.0)\n", "Requirement already satisfied: more-itertools in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (8.12.0)\n", "Requirement already satisfied: tiktoken in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai-whisper) (0.3.3)\n", "Requirement already satisfied: llvmlite<0.41,>=0.40.0dev0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from numba->openai-whisper) (0.40.0)\n", "Requirement already satisfied: regex>=2022.1.18 in c:\\users\\user\\anaconda3\\lib\\site-packages (from tiktoken->openai-whisper) (2022.7.9)\n", "Requirement already satisfied: requests>=2.26.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from tiktoken->openai-whisper) (2.31.0)\n", "Requirement already satisfied: filelock in c:\\users\\user\\anaconda3\\lib\\site-packages (from torch->openai-whisper) (3.9.0)\n", "Requirement already satisfied: typing-extensions in c:\\users\\user\\anaconda3\\lib\\site-packages (from torch->openai-whisper) (4.8.0)\n", "Requirement already satisfied: sympy in c:\\users\\user\\anaconda3\\lib\\site-packages (from torch->openai-whisper) (1.11.1)\n", "Requirement already satisfied: networkx in c:\\users\\user\\anaconda3\\lib\\site-packages (from torch->openai-whisper) (3.1)\n", "Requirement already satisfied: jinja2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from torch->openai-whisper) (3.1.2)\n", "Requirement already satisfied: colorama in c:\\users\\user\\anaconda3\\lib\\site-packages (from tqdm->openai-whisper) (0.4.6)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken->openai-whisper) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken->openai-whisper) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken->openai-whisper) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.26.0->tiktoken->openai-whisper) (2023.7.22)\n", "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from jinja2->torch->openai-whisper) (2.1.1)\n", "Requirement already satisfied: mpmath>=0.19 in c:\\users\\user\\anaconda3\\lib\\site-packages (from sympy->torch->openai-whisper) (1.3.0)\n" ] } ], "source": [ "!pip install -U openai-whisper" ] }, { "cell_type": "markdown", "metadata": { "id": "rh2gr_ySZndV" }, "source": [ "# **將軟體包更新到最新版本**" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "id": "oZTj2_eVcyWA" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting git+https://github.com/openai/whisper.git" ] }, { "name": "stderr", "output_type": "stream", "text": [ " Running command git clone --filter=blob:none --quiet https://github.com/openai/whisper.git 'C:\\Users\\User\\AppData\\Local\\Temp\\pip-req-build-4d1tu9pt'\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", " Cloning https://github.com/openai/whisper.git to c:\\users\\user\\appdata\\local\\temp\\pip-req-build-4d1tu9pt\n", " Resolved https://github.com/openai/whisper.git to commit 1cea4357687b676b293cb5473e1ade25f5b1cef7\n", " Installing build dependencies: started\n", " Installing build dependencies: finished with status 'done'\n", " Getting requirements to build wheel: started\n", " Getting requirements to build wheel: finished with status 'done'\n", " Preparing metadata (pyproject.toml): started\n", " Preparing metadata (pyproject.toml): finished with status 'done'\n", "Building wheels for collected packages: openai-whisper\n", " Building wheel for openai-whisper (pyproject.toml): started\n", " Building wheel for openai-whisper (pyproject.toml): finished with status 'done'\n", " Created wheel for openai-whisper: filename=openai_whisper-20231106-py3-none-any.whl size=810671 sha256=d044449efeadecaaac6db643ef56907dfccacf08ae11f5a79531acf7cdacfbbe\n", " Stored in directory: C:\\Users\\User\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-2h7i6okj\\wheels\\1f\\1d\\98\\9583695e6695a6ac0ad42d87511097dce5ba486647dbfecb0e\n", "Successfully built openai-whisper\n", "Installing collected packages: openai-whisper\n", " Attempting uninstall: openai-whisper\n", " Found existing installation: openai-whisper 20231106\n", " Uninstalling openai-whisper-20231106:\n", " Successfully uninstalled openai-whisper-20231106\n", "Successfully installed openai-whisper-20231106\n" ] } ], "source": [ "!pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git" ] }, { "cell_type": "markdown", "metadata": { "id": "PgaD3q4OZcfr" }, "source": [ "# **以下命令將使用medium模型在音訊檔案中轉錄語音**\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "BkRtgTCodyH-" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Skipping audio.flac due to RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.flac: No such file or directory\n", "\n", "\n", "Skipping audio.mp3 due to RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.mp3: No such file or directory\n", "\n", "\n", "Skipping audio.wav due to RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.wav: No such file or directory\n", "\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 58, in load_audio\n", " out = run(cmd, capture_output=True, check=True).stdout\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\subprocess.py\", line 571, in run\n", " raise CalledProcessError(retcode, process.args,\n", "subprocess.CalledProcessError: Command '['ffmpeg', '-nostdin', '-threads', '0', '-i', 'audio.flac', '-f', 's16le', '-ac', '1', '-acodec', 'pcm_s16le', '-ar', '16000', '-']' returned non-zero exit status 1.\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 478, in cli\n", " result = transcribe(model, audio_path, temperature=temperature, **args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 122, in transcribe\n", " mel = log_mel_spectrogram(audio, model.dims.n_mels, padding=N_SAMPLES)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 140, in log_mel_spectrogram\n", " audio = load_audio(audio)\n", " ^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 60, in load_audio\n", " raise RuntimeError(f\"Failed to load audio: {e.stderr.decode()}\") from e\n", "RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.flac: No such file or directory\n", "\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 58, in load_audio\n", " out = run(cmd, capture_output=True, check=True).stdout\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\subprocess.py\", line 571, in run\n", " raise CalledProcessError(retcode, process.args,\n", "subprocess.CalledProcessError: Command '['ffmpeg', '-nostdin', '-threads', '0', '-i', 'audio.mp3', '-f', 's16le', '-ac', '1', '-acodec', 'pcm_s16le', '-ar', '16000', '-']' returned non-zero exit status 1.\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 478, in cli\n", " result = transcribe(model, audio_path, temperature=temperature, **args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 122, in transcribe\n", " mel = log_mel_spectrogram(audio, model.dims.n_mels, padding=N_SAMPLES)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 140, in log_mel_spectrogram\n", " audio = load_audio(audio)\n", " ^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 60, in load_audio\n", " raise RuntimeError(f\"Failed to load audio: {e.stderr.decode()}\") from e\n", "RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.mp3: No such file or directory\n", "\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 58, in load_audio\n", " out = run(cmd, capture_output=True, check=True).stdout\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\subprocess.py\", line 571, in run\n", " raise CalledProcessError(retcode, process.args,\n", "subprocess.CalledProcessError: Command '['ffmpeg', '-nostdin', '-threads', '0', '-i', 'audio.wav', '-f', 's16le', '-ac', '1', '-acodec', 'pcm_s16le', '-ar', '16000', '-']' returned non-zero exit status 1.\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 478, in cli\n", " result = transcribe(model, audio_path, temperature=temperature, **args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 122, in transcribe\n", " mel = log_mel_spectrogram(audio, model.dims.n_mels, padding=N_SAMPLES)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 140, in log_mel_spectrogram\n", " audio = load_audio(audio)\n", " ^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 60, in load_audio\n", " raise RuntimeError(f\"Failed to load audio: {e.stderr.decode()}\") from e\n", "RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "audio.wav: No such file or directory\n", "\n", "\n" ] } ], "source": [ "!whisper audio.flac audio.mp3 audio.wav --model medium" ] }, { "cell_type": "markdown", "metadata": { "id": "Qtn89HW-Z5-y" }, "source": [ "# **下載中文語言包**" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "id": "mpgdHsXGo7BZ" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Skipping chinese.wav due to RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "chinese.wav: No such file or directory\n", "\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 58, in load_audio\n", " out = run(cmd, capture_output=True, check=True).stdout\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\subprocess.py\", line 571, in run\n", " raise CalledProcessError(retcode, process.args,\n", "subprocess.CalledProcessError: Command '['ffmpeg', '-nostdin', '-threads', '0', '-i', 'chinese.wav', '-f', 's16le', '-ac', '1', '-acodec', 'pcm_s16le', '-ar', '16000', '-']' returned non-zero exit status 1.\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 478, in cli\n", " result = transcribe(model, audio_path, temperature=temperature, **args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 122, in transcribe\n", " mel = log_mel_spectrogram(audio, model.dims.n_mels, padding=N_SAMPLES)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 140, in log_mel_spectrogram\n", " audio = load_audio(audio)\n", " ^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 60, in load_audio\n", " raise RuntimeError(f\"Failed to load audio: {e.stderr.decode()}\") from e\n", "RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "chinese.wav: No such file or directory\n", "\n", "\n" ] } ], "source": [ "!whisper chinese.wav --language Chinese" ] }, { "cell_type": "markdown", "metadata": { "id": "LKlGrnh2a5jx" }, "source": [ "# **可將語言翻譯成英文**" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "id": "ZWV92M68atLr" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Skipping chinese.wav due to RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "chinese.wav: No such file or directory\n", "\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 58, in load_audio\n", " out = run(cmd, capture_output=True, check=True).stdout\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\subprocess.py\", line 571, in run\n", " raise CalledProcessError(retcode, process.args,\n", "subprocess.CalledProcessError: Command '['ffmpeg', '-nostdin', '-threads', '0', '-i', 'chinese.wav', '-f', 's16le', '-ac', '1', '-acodec', 'pcm_s16le', '-ar', '16000', '-']' returned non-zero exit status 1.\n", "\n", "The above exception was the direct cause of the following exception:\n", "\n", "Traceback (most recent call last):\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 478, in cli\n", " result = transcribe(model, audio_path, temperature=temperature, **args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\transcribe.py\", line 122, in transcribe\n", " mel = log_mel_spectrogram(audio, model.dims.n_mels, padding=N_SAMPLES)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 140, in log_mel_spectrogram\n", " audio = load_audio(audio)\n", " ^^^^^^^^^^^^^^^^^\n", " File \"C:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\audio.py\", line 60, in load_audio\n", " raise RuntimeError(f\"Failed to load audio: {e.stderr.decode()}\") from e\n", "RuntimeError: Failed to load audio: ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers\n", "\n", " built with gcc 10.2.1 (GCC) 20200726\n", "\n", " configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --enable-librav1e --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf\n", "\n", " libavutil 56. 51.100 / 56. 51.100\n", "\n", " libavcodec 58. 91.100 / 58. 91.100\n", "\n", " libavformat 58. 45.100 / 58. 45.100\n", "\n", " libavdevice 58. 10.100 / 58. 10.100\n", "\n", " libavfilter 7. 85.100 / 7. 85.100\n", "\n", " libswscale 5. 7.100 / 5. 7.100\n", "\n", " libswresample 3. 7.100 / 3. 7.100\n", "\n", " libpostproc 55. 7.100 / 55. 7.100\n", "\n", "chinese.wav: No such file or directory\n", "\n", "\n" ] } ], "source": [ "!whisper chinese.wav --language Chinese --task translate" ] }, { "cell_type": "markdown", "metadata": { "id": "lLMe8B9aZiim" }, "source": [ "# **下載翻譯API**" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "id": "bADHSOBhvV04" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: openai in c:\\users\\user\\anaconda3\\lib\\site-packages (0.28.1)\n", "Requirement already satisfied: requests>=2.20 in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai) (2.31.0)\n", "Requirement already satisfied: tqdm in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai) (4.65.0)\n", "Requirement already satisfied: aiohttp in c:\\users\\user\\anaconda3\\lib\\site-packages (from openai) (3.8.3)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.20->openai) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.20->openai) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.20->openai) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests>=2.20->openai) (2023.7.22)\n", "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (22.1.0)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (6.0.2)\n", "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (4.0.2)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (1.8.1)\n", "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (1.3.3)\n", "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from aiohttp->openai) (1.2.0)\n", "Requirement already satisfied: colorama in c:\\users\\user\\anaconda3\\lib\\site-packages (from tqdm->openai) (0.4.6)\n" ] } ], "source": [ "\n", "!pip install openai" ] }, { "cell_type": "markdown", "metadata": { "id": "KtJj-H2vZpzf" }, "source": [ "# **匯入檔案的CODE**" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "qeHuyE41cmIl" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: gradio_client in c:\\users\\user\\anaconda3\\lib\\site-packages (0.7.0)\n", "Requirement already satisfied: fsspec in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (2023.10.0)\n", "Requirement already satisfied: httpx in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (0.25.1)\n", "Requirement already satisfied: huggingface-hub>=0.13.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (0.19.1)\n", "Requirement already satisfied: packaging in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (23.0)\n", "Requirement already satisfied: requests~=2.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (2.31.0)\n", "Requirement already satisfied: typing-extensions~=4.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (4.8.0)\n", "Requirement already satisfied: websockets<12.0,>=10.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from gradio_client) (11.0.3)\n", "Requirement already satisfied: filelock in c:\\users\\user\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.13.0->gradio_client) (3.9.0)\n", "Requirement already satisfied: tqdm>=4.42.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.13.0->gradio_client) (4.65.0)\n", "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from huggingface-hub>=0.13.0->gradio_client) (6.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio_client) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio_client) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio_client) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests~=2.0->gradio_client) (2023.7.22)\n", "Requirement already satisfied: anyio in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpx->gradio_client) (3.7.1)\n", "Requirement already satisfied: httpcore in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpx->gradio_client) (1.0.2)\n", "Requirement already satisfied: sniffio in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpx->gradio_client) (1.2.0)\n", "Requirement already satisfied: colorama in c:\\users\\user\\anaconda3\\lib\\site-packages (from tqdm>=4.42.1->huggingface-hub>=0.13.0->gradio_client) (0.4.6)\n", "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\user\\anaconda3\\lib\\site-packages (from httpcore->httpx->gradio_client) (0.14.0)\n" ] } ], "source": [ "!pip install gradio_client" ] }, { "cell_type": "markdown", "metadata": { "id": "ijGRue6X4Yuk" }, "source": [ "#正確的\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "id": "zGnrVKblRfXu" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "c:\\Users\\User\\Downloads\\whisper\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Cloning into 'whisper'...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: transformers in c:\\users\\user\\anaconda3\\lib\\site-packages (from -r requirements.txt (line 1)) (2.1.1)\n", "Requirement already satisfied: numpy in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (1.24.3)\n", "Requirement already satisfied: boto3 in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (1.24.28)\n", "Requirement already satisfied: requests in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (2.31.0)\n", "Requirement already satisfied: tqdm in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (4.65.0)\n", "Requirement already satisfied: regex in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (2022.7.9)\n", "Collecting sentencepiece (from transformers->-r requirements.txt (line 1))\n", " Downloading sentencepiece-0.1.99-cp311-cp311-win_amd64.whl (977 kB)\n", " ---------------------------------------- 0.0/977.5 kB ? eta -:--:--\n", " - ------------------------------------- 30.7/977.5 kB 1.3 MB/s eta 0:00:01\n", " - ----------------------------------- 41.0/977.5 kB 487.6 kB/s eta 0:00:02\n", " ----- -------------------------------- 143.4/977.5 kB 1.1 MB/s eta 0:00:01\n", " --------- ---------------------------- 235.5/977.5 kB 1.3 MB/s eta 0:00:01\n", " ------------- ------------------------ 337.9/977.5 kB 1.5 MB/s eta 0:00:01\n", " --------------- ---------------------- 389.1/977.5 kB 1.6 MB/s eta 0:00:01\n", " --------------- ---------------------- 409.6/977.5 kB 1.3 MB/s eta 0:00:01\n", " ------------------- ------------------ 491.5/977.5 kB 1.3 MB/s eta 0:00:01\n", " --------------------------- ---------- 696.3/977.5 kB 1.8 MB/s eta 0:00:01\n", " --------------------------- ---------- 706.6/977.5 kB 1.5 MB/s eta 0:00:01\n", " ------------------------------- ------ 809.0/977.5 kB 1.6 MB/s eta 0:00:01\n", " ----------------------------------- -- 901.1/977.5 kB 1.6 MB/s eta 0:00:01\n", " ----------------------------------- -- 901.1/977.5 kB 1.6 MB/s eta 0:00:01\n", " ------------------------------------- 972.8/977.5 kB 1.5 MB/s eta 0:00:01\n", " -------------------------------------- 977.5/977.5 kB 1.5 MB/s eta 0:00:00\n", "Requirement already satisfied: sacremoses in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers->-r requirements.txt (line 1)) (0.0.43)\n", "Requirement already satisfied: botocore<1.28.0,>=1.27.28 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers->-r requirements.txt (line 1)) (1.27.59)\n", "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers->-r requirements.txt (line 1)) (0.10.0)\n", "Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers->-r requirements.txt (line 1)) (0.6.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers->-r requirements.txt (line 1)) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers->-r requirements.txt (line 1)) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers->-r requirements.txt (line 1)) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers->-r requirements.txt (line 1)) (2023.7.22)\n", "Requirement already satisfied: six in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers->-r requirements.txt (line 1)) (1.16.0)\n", "Requirement already satisfied: click in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers->-r requirements.txt (line 1)) (8.0.4)\n", "Requirement already satisfied: joblib in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers->-r requirements.txt (line 1)) (1.2.0)\n", "Requirement already satisfied: colorama in c:\\users\\user\\anaconda3\\lib\\site-packages (from tqdm->transformers->-r requirements.txt (line 1)) (0.4.6)\n", "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from botocore<1.28.0,>=1.27.28->boto3->transformers->-r requirements.txt (line 1)) (2.8.2)\n", "Installing collected packages: sentencepiece\n", "Successfully installed sentencepiece-0.1.99\n" ] } ], "source": [ "!git clone https://huggingface.co/spaces/openai/whisper\n", "%cd whisper\n", "!pip install -r requirements.txt" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "id": "XNHE7YBAQtQd" }, "outputs": [ { "ename": "OutOfMemoryError", "evalue": "CUDA out of memory. Tried to allocate 38.00 MiB (GPU 0; 8.00 GiB total capacity; 6.91 GiB already allocated; 0 bytes free; 7.25 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mOutOfMemoryError\u001b[0m Traceback (most recent call last)", "\u001b[1;32mc:\\Users\\User\\Downloads\\王茗顥大帥哥whisper-2.ipynb Cell 19\u001b[0m line \u001b[0;36m8\n\u001b[0;32m 3\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mgradio\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mgr\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mwhisper\u001b[39;00m\n\u001b[1;32m----> 8\u001b[0m model \u001b[39m=\u001b[39m whisper\u001b[39m.\u001b[39mload_model(\u001b[39m\"\u001b[39m\u001b[39mtiny\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 12\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39minference\u001b[39m(audio):\n\u001b[0;32m 13\u001b[0m audio \u001b[39m=\u001b[39m whisper\u001b[39m.\u001b[39mload_audio(audio)\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\whisper\\__init__.py:146\u001b[0m, in \u001b[0;36mload_model\u001b[1;34m(name, device, download_root, in_memory)\u001b[0m\n\u001b[0;32m 139\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m(\n\u001b[0;32m 140\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mModel \u001b[39m\u001b[39m{\u001b[39;00mname\u001b[39m}\u001b[39;00m\u001b[39m not found; available models = \u001b[39m\u001b[39m{\u001b[39;00mavailable_models()\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m\n\u001b[0;32m 141\u001b[0m )\n\u001b[0;32m 143\u001b[0m \u001b[39mwith\u001b[39;00m (\n\u001b[0;32m 144\u001b[0m io\u001b[39m.\u001b[39mBytesIO(checkpoint_file) \u001b[39mif\u001b[39;00m in_memory \u001b[39melse\u001b[39;00m \u001b[39mopen\u001b[39m(checkpoint_file, \u001b[39m\"\u001b[39m\u001b[39mrb\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 145\u001b[0m ) \u001b[39mas\u001b[39;00m fp:\n\u001b[1;32m--> 146\u001b[0m checkpoint \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mload(fp, map_location\u001b[39m=\u001b[39mdevice)\n\u001b[0;32m 147\u001b[0m \u001b[39mdel\u001b[39;00m checkpoint_file\n\u001b[0;32m 149\u001b[0m dims \u001b[39m=\u001b[39m ModelDimensions(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mcheckpoint[\u001b[39m\"\u001b[39m\u001b[39mdims\u001b[39m\u001b[39m\"\u001b[39m])\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:809\u001b[0m, in \u001b[0;36mload\u001b[1;34m(f, map_location, pickle_module, weights_only, **pickle_load_args)\u001b[0m\n\u001b[0;32m 807\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mRuntimeError\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[0;32m 808\u001b[0m \u001b[39mraise\u001b[39;00m pickle\u001b[39m.\u001b[39mUnpicklingError(UNSAFE_MESSAGE \u001b[39m+\u001b[39m \u001b[39mstr\u001b[39m(e)) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m--> 809\u001b[0m \u001b[39mreturn\u001b[39;00m _load(opened_zipfile, map_location, pickle_module, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpickle_load_args)\n\u001b[0;32m 810\u001b[0m \u001b[39mif\u001b[39;00m weights_only:\n\u001b[0;32m 811\u001b[0m \u001b[39mtry\u001b[39;00m:\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:1172\u001b[0m, in \u001b[0;36m_load\u001b[1;34m(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)\u001b[0m\n\u001b[0;32m 1170\u001b[0m unpickler \u001b[39m=\u001b[39m UnpicklerWrapper(data_file, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mpickle_load_args)\n\u001b[0;32m 1171\u001b[0m unpickler\u001b[39m.\u001b[39mpersistent_load \u001b[39m=\u001b[39m persistent_load\n\u001b[1;32m-> 1172\u001b[0m result \u001b[39m=\u001b[39m unpickler\u001b[39m.\u001b[39mload()\n\u001b[0;32m 1174\u001b[0m torch\u001b[39m.\u001b[39m_utils\u001b[39m.\u001b[39m_validate_loaded_sparse_tensors()\n\u001b[0;32m 1176\u001b[0m \u001b[39mreturn\u001b[39;00m result\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:1142\u001b[0m, in \u001b[0;36m_load..persistent_load\u001b[1;34m(saved_id)\u001b[0m\n\u001b[0;32m 1140\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 1141\u001b[0m nbytes \u001b[39m=\u001b[39m numel \u001b[39m*\u001b[39m torch\u001b[39m.\u001b[39m_utils\u001b[39m.\u001b[39m_element_size(dtype)\n\u001b[1;32m-> 1142\u001b[0m typed_storage \u001b[39m=\u001b[39m load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))\n\u001b[0;32m 1144\u001b[0m \u001b[39mreturn\u001b[39;00m typed_storage\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:1116\u001b[0m, in \u001b[0;36m_load..load_tensor\u001b[1;34m(dtype, numel, key, location)\u001b[0m\n\u001b[0;32m 1112\u001b[0m storage \u001b[39m=\u001b[39m zip_file\u001b[39m.\u001b[39mget_storage_from_record(name, numel, torch\u001b[39m.\u001b[39mUntypedStorage)\u001b[39m.\u001b[39m_typed_storage()\u001b[39m.\u001b[39m_untyped_storage\n\u001b[0;32m 1113\u001b[0m \u001b[39m# TODO: Once we decide to break serialization FC, we can\u001b[39;00m\n\u001b[0;32m 1114\u001b[0m \u001b[39m# stop wrapping with TypedStorage\u001b[39;00m\n\u001b[0;32m 1115\u001b[0m typed_storage \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mstorage\u001b[39m.\u001b[39mTypedStorage(\n\u001b[1;32m-> 1116\u001b[0m wrap_storage\u001b[39m=\u001b[39mrestore_location(storage, location),\n\u001b[0;32m 1117\u001b[0m dtype\u001b[39m=\u001b[39mdtype,\n\u001b[0;32m 1118\u001b[0m _internal\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[0;32m 1120\u001b[0m \u001b[39mif\u001b[39;00m typed_storage\u001b[39m.\u001b[39m_data_ptr() \u001b[39m!=\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m 1121\u001b[0m loaded_storages[key] \u001b[39m=\u001b[39m typed_storage\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:1083\u001b[0m, in \u001b[0;36m_get_restore_location..restore_location\u001b[1;34m(storage, location)\u001b[0m\n\u001b[0;32m 1082\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mrestore_location\u001b[39m(storage, location):\n\u001b[1;32m-> 1083\u001b[0m \u001b[39mreturn\u001b[39;00m default_restore_location(storage, map_location)\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:217\u001b[0m, in \u001b[0;36mdefault_restore_location\u001b[1;34m(storage, location)\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdefault_restore_location\u001b[39m(storage, location):\n\u001b[0;32m 216\u001b[0m \u001b[39mfor\u001b[39;00m _, _, fn \u001b[39min\u001b[39;00m _package_registry:\n\u001b[1;32m--> 217\u001b[0m result \u001b[39m=\u001b[39m fn(storage, location)\n\u001b[0;32m 218\u001b[0m \u001b[39mif\u001b[39;00m result \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 219\u001b[0m \u001b[39mreturn\u001b[39;00m result\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\serialization.py:187\u001b[0m, in \u001b[0;36m_cuda_deserialize\u001b[1;34m(obj, location)\u001b[0m\n\u001b[0;32m 185\u001b[0m \u001b[39mreturn\u001b[39;00m torch\u001b[39m.\u001b[39mUntypedStorage(obj\u001b[39m.\u001b[39mnbytes(), device\u001b[39m=\u001b[39mtorch\u001b[39m.\u001b[39mdevice(location))\n\u001b[0;32m 186\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m--> 187\u001b[0m \u001b[39mreturn\u001b[39;00m obj\u001b[39m.\u001b[39mcuda(device)\n", "File \u001b[1;32mc:\\Users\\User\\anaconda3\\Lib\\site-packages\\torch\\_utils.py:81\u001b[0m, in \u001b[0;36m_cuda\u001b[1;34m(self, device, non_blocking, **kwargs)\u001b[0m\n\u001b[0;32m 79\u001b[0m \u001b[39mreturn\u001b[39;00m new_type(indices, values, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msize())\n\u001b[0;32m 80\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m---> 81\u001b[0m untyped_storage \u001b[39m=\u001b[39m torch\u001b[39m.\u001b[39mUntypedStorage(\n\u001b[0;32m 82\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msize(), device\u001b[39m=\u001b[39mtorch\u001b[39m.\u001b[39mdevice(\u001b[39m\"\u001b[39m\u001b[39mcuda\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 83\u001b[0m )\n\u001b[0;32m 84\u001b[0m untyped_storage\u001b[39m.\u001b[39mcopy_(\u001b[39mself\u001b[39m, non_blocking)\n\u001b[0;32m 85\u001b[0m \u001b[39mreturn\u001b[39;00m untyped_storage\n", "\u001b[1;31mOutOfMemoryError\u001b[0m: CUDA out of memory. Tried to allocate 38.00 MiB (GPU 0; 8.00 GiB total capacity; 6.91 GiB already allocated; 0 bytes free; 7.25 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF" ] } ], "source": [ "import os\n", "os.system(\"pip install git+https://github.com/openai/whisper.git\")\n", "import gradio as gr\n", "import whisper\n", "\n", "\n", "\n", "model = whisper.load_model(\"tiny\")\n", "\n", "\n", "\n", "def inference(audio):\n", " audio = whisper.load_audio(audio)\n", " audio = whisper.pad_or_trim(audio)\n", "\n", " mel = whisper.log_mel_spectrogram(audio).to(model.device)\n", "\n", " _, probs = model.detect_language(mel)\n", "\n", " options = whisper.DecodingOptions(fp16 = False)\n", " result = whisper.decode(model, mel, options)\n", "\n", " print(result.text)\n", " return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)\n", "\n", "iface = gr.Interface(\n", " fn=inference,\n", " inputs=gr.Audio(type=\"filepath\", label=\"上传音频文件 (.mp3, .wav等)\"),\n", " outputs=\"text\"\n", ")\n", "\n", "# 启动 Gradio 界面\n", "iface.launch()\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "id": "SQsjMmicSV0m" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: transformers in c:\\users\\user\\anaconda3\\lib\\site-packages (2.1.1)\n", "Requirement already satisfied: numpy in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (1.24.3)\n", "Requirement already satisfied: boto3 in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (1.24.28)\n", "Requirement already satisfied: requests in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (2.31.0)\n", "Requirement already satisfied: tqdm in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (4.65.0)\n", "Requirement already satisfied: regex in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (2022.7.9)\n", "Requirement already satisfied: sentencepiece in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (0.1.99)\n", "Requirement already satisfied: sacremoses in c:\\users\\user\\anaconda3\\lib\\site-packages (from transformers) (0.0.43)\n", "Requirement already satisfied: botocore<1.28.0,>=1.27.28 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers) (1.27.59)\n", "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers) (0.10.0)\n", "Requirement already satisfied: s3transfer<0.7.0,>=0.6.0 in c:\\users\\user\\anaconda3\\lib\\site-packages (from boto3->transformers) (0.6.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers) (1.26.16)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\anaconda3\\lib\\site-packages (from requests->transformers) (2023.7.22)\n", "Requirement already satisfied: six in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers) (1.16.0)\n", "Requirement already satisfied: click in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers) (8.0.4)\n", "Requirement already satisfied: joblib in c:\\users\\user\\anaconda3\\lib\\site-packages (from sacremoses->transformers) (1.2.0)\n", "Requirement already satisfied: colorama in c:\\users\\user\\anaconda3\\lib\\site-packages (from tqdm->transformers) (0.4.6)\n", "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\\users\\user\\anaconda3\\lib\\site-packages (from botocore<1.28.0,>=1.27.28->boto3->transformers) (2.8.2)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install transformers\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5i1LGotLbqip", "outputId": "111369a7-bd4e-4843-9737-a39c468012ec" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " If you find it very complicated, then you must not worry about it. Don't just go into the mind to think that it is complicated, but in fact, it is even more complicated than you think. If we are not able to understand the meaning of the words of the words today, then we will not understand it yesterday. If you have found out that the meaning of the words of the words of the words of the four words, please let me know. Hello everyone, I am 18 years old today.\n" ] } ], "source": [ "Chinese_to_english = model.transcribe(audio,task='translate')\n", "print(Chinese_to_english[\"text\"])" ] }, { "cell_type": "markdown", "metadata": { "id": "3lUCRSkhZ9kQ" }, "source": [ "# **輸入YouTube網址來實現語音轉文字中英文皆可**" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "owz-tvQioMvL" }, "outputs": [], "source": [ "import whisper\n", "import torch\n", "import os" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "kK_fJz-CRv6O", "outputId": "5f80f175-9de8-4035-9d67-4cc684859f41" }, "outputs": [ { "data": { "text/plain": [ "'cpu'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "device = \"cpu\" if torch.cuda.is_available() else \"cpu\"\n", "device" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "POMpkyjQR9IN" }, "outputs": [], "source": [ "whisper_model = whisper.load_model(\"large\", device=device)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "H5lr_kCtSJyF", "outputId": "975e6a4b-bc3b-45c9-c897-5ae981815da1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/57.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m41.0/57.6 kB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.6/57.6 kB\u001b[0m \u001b[31m1.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } ], "source": [ "!pip -qqq install pytube" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jZql4_M5SSMq" }, "outputs": [], "source": [ "from pytube import YouTube\n", "def video_to_audio(vedio_URL,destination,final_filename):\n", " vedio = YouTube(vedio_URL)\n", "\n", " audio = vedio.streams.filter(only_audio=True).first()\n", "\n", " output = audio.download(output_path = destination)\n", "\n", " _,ext = os.path.splitext (output)\n", " new_file = final_filename + '.mp3'\n", "\n", " os.rename(output,new_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jN10OsquTtEI" }, "outputs": [], "source": [ "video_URL = 'https://www.youtube.com/watch?v=s0RB1X1YYdU' #網址位置\n", "destination =\".\"\n", "final_filename = \"motivational_speech\" #將影片轉換為mp3\n", "video_to_audio(video_URL, destination, final_filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "EhcNzSZFUkgF" }, "outputs": [], "source": [ "audio_file=\"motivational_speech.mp3\" #匯入mp3檔案並且語音轉文字\n", "result = whisper_model.transcribe(audio_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "yiWLgZzIVwJD", "outputId": "6091e9a1-bf48-47ed-fe18-e84891ca2123" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "今天是我們在倫敦市區最後一天然後我們接下來就要去倫敦以外的探索那我們因為這樣子租了一台車然後是跑車跑車嗎?不是跑車啦SUV啦那我不開我只開跑車我哪有跟你說跑車SUV因為我們要放五個人的行李對我們是後車廂很大的跑車OK好好好那我們這個都已經先預約好了然後我是選Audi Q7該不會就是那一台吧我個人是蠻喜歡的我剛剛就是看了很多之後我覺得最適合我們因為它後面整個那個後車廂都可以蓋下來這個嗎?對啊那可能預算要三倍好我們來拿車了這個是我們的職業國際駕駛員這是你的卡但是你手上的這是我的卡車子的資料會在他的名字裡面OK我們可以換嗎?我們現在要做的是我們要付款給那台車我們要付款給你OK然後付款給他的車OK所以我的已經付款了你付款了但是你還沒有付款OK所以我們還沒有完成交易明白所以我們現在要付款然後付款給你的車OK明白不知道為什麼新加坡卡這麼沒用這個申請的駕駛人的名字新加坡卡要跟駕駛人名字一樣我好奇我看到Royce在那邊停車一天要租多少錢?我們沒有租車租金最少要租兩天一天要租15000元一天要租15000元一天租15000元喔對哇Peter說這邊是厲害的租車廠對啊這裡都是厲害的車子阿滴說他想要租這台Royce Nice我們剛剛有問一天租6萬塊然後押金60萬對啊你看我們這樣子分下來一個人大概一萬出頭還可以吧還可以我們開在路上一堆女生就直接來大G渣男開大G這就是我們的渣男欸開不起來有開得起來渣男開大G關起來上堂的聲音有這是Joeman教我的Joeman這個渣男看這個跟大家介紹一下我的車賓利哇欸賓利系列大賓利系列欸這個這個怎麼樣寶馬欸這邊真的是奢華區欸對啊來跟大家介紹一下我的車Aston Martin你們的車真的很好這不是全部的對啊我們這裡沒有Ferrari和Lamborghini我們直接偷偷上去那台車對啊我們偷偷上去我們開著沒有人來對太巧了吧欸你看這個渣男視野Yo他們真的變好矮喔這整個世界都變矮了一截你看你就是適合開這種車啊Peter哥哥以你的肌肉量這個就是我的車欸這就是你的車欸超級你的車這應該叫大P它不應該叫大G大P它還開機了現在的狀況是我之前租車都是用我的信用卡我的名字但是是用哥哥的國際駕照所以駕駛人是他但他後來喬喬之後說不可以這樣就是一定要由駕駛人支付跟信用卡所以可能Maybe他會覺得如果是駕駛人出什麼包然後如果我逃跑的話他就沒有任何人可以索賠Maybe是這樣我要上那台賓利了他剛有跟我們說我們可以就是去摸摸啊去看看這些車子摸摸有包括開開嗎應該可以吧我們兩個在我們兩個在這邊大delay整個團體的進度這台是給你開啦不要說對你不好這台給我開喔這台給你開這台是什麼賓利哇哇它這個經典的這個很漂亮的儀表板還有它的這個Clock哇坐起來舒服你看一整個面這樣子簡約設計這樣過去怪色的我要趕快出去剛剛有講嗎我租的是Audi QQ8還是Q7系列就是它後面可以壓下來所以我們五個人的行李都可以放得上去好的我們要上車了這就是我們的Q這是Q7還是Q8這是Q7還是Q8Q8你看它這個後車廂很大它這邊其實是兩個椅子可以拉起來它這個按鈕在這邊就是可以多兩個椅子但是我們把它都往下所以這邊後面可以放大家的行李箱好的租到車了現在在收集它我們要去接大家對它跟Google Maps一樣的這台車真的是滿舒適的非常多空間好那我們待會就是回去民宿接大家之後一路要開到牛津要花一個多小時一個半小時左右的車程然後我們在牛津會有一系列的拍攝結束再去到我們這趟最後的一個點是一個在比較西邊的16世紀的城堡最後的兩天會住在城堡怪色掌聲給Peter哥哥再接一次開車謝謝Peter哥哥這趟幫我們開車我們現在要還車的地方了Peter覺得這次自駕的英國自駕的感想如何我覺得開車比台灣舒服很多但這邊的路比較小對但是整個大家的那個擠壓感比較沒有那麼嚴重因為台灣我大部分開的時候真的機車真的太多它會是有點危險的感覺然後車子也比較不會那麼禮讓對我們在英國好像沒有被巴過對沒有被巴過所以我覺得還蠻舒服的那雖然有的時候會有點小但是我覺得還是比較舒服跟台灣比起來那左駕呢對你來說因為上次去沖繩已經駕過一次了然後已經有練習過了所以這次已經非常輕易的上手了了解我們這次是跟Hertz租車然後我們租的車型是Audi的Q8它就是後面比較大其實我一開始一直在研究的時候我就因為知道有五個人然後五個行李箱所以我就已經找了一個我看起來覺得最大的SUV了因為再往上搭就是那種小卡車就會更貴結果我們的位置還是不太夠對就是後來大謙要抱著自己的行李箱在前面我們才拆了一下但是還算可以啦就是後面整個這樣拆開來才是蠻大的後面蠻大屁股蠻大的我喜歡然後呢我們這樣子租車三天下來一共是4萬2台幣What4萬2對我們會用四個人拆因為Peter哥哥幫忙駕駛所以哥哥跟Alicia算一組沒關係吧所以我們會四個人拆這樣子的話一個人是一萬塊左右等於是三天但是我覺得還是蠻划算的因為你講喔我們第一天等於是我們要我們直接從市區就直接取車然後去到我們要去到的就是比較旁邊的Bristol然後回來的路上我們也可以去到很多可能沒有車子不能去的景點像巨石鎮羅馬浴場所以我覺得整體來說還不錯其實我現在認真覺得什麼東西跟那個馬車比較起來都是很不合適的對所以我剛剛聽到雖然有嚇到但是喔好像在坐馬車對對對這時候大家應該還不知道坐馬車是什麼大家繼續往下看繼續往下看就知道馬車是什麼奇怪的盤子形成了好所以這次是我們的體驗所以蠻推薦大家如果可以就是在倫敦之外想要玩一些其他的城鎮的話可以在倫敦市區租車然後呢像我們一樣最後一天回來機場換車像這樣我們也不用再多一趟Uber的錢因為去那邊就要100塊對對對對來回這樣就200所以少100也算省錢對蠻好的好以上給大家參考好讚那接下來還會繼續阿滴日常我只是今天是我們最後一天了但是只是我把這個最後變成片段我想說租車當作是一集完整的所以接下來還會再日更好幾天這樣子會是繼續帶大家看說我們搭著車子都是去了哪裡玩這樣好拜拜\n" ] } ], "source": [ "print(result[\"text\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "koyK5ySbW-a6" }, "outputs": [], "source": [ "Chinese_to_english = whisper_model.transcribe(audio_file,task='translate')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "H_jql0n2a4P9", "outputId": "d3d7db2d-5fb8-4ca9-f04f-24dd91d4af39" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Today is our last day in London We're going to explore London We rented a car A sports car A sports car? Not a sports car, an SUV I'm not driving I only drive a sports car I didn't say SUV SUV, because we're putting five people in We're... We're a sports car with a big trunk Oh, okay Okay, we've already made a reservation I'm choosing the Audi Q7 Is it that one? I... I... I personally quite like it I just... After seeing a lot I think it's the most suitable for us Because the whole rear compartment Can be covered This one? This one? That might cost three times the budget Okay, let's get the car This is our... Professional international driver Your card It's my card My card The card unfortunately would have to be in his name Okay Can we change... So what we've done is We've obviously charged the rental to that car Which we're going to have to refund to you Okay And charge everything on his car Okay So mine's already charged We charged the rental But you declined our deposit anyways Okay So we couldn't complete the transactions on there So what we'll do is We'll refund the rental cost And charge him the full rental and deposit on his Okay I don't know why the credit card Can only be used To apply for the driver's name The credit card has to be the same as the driver's name Peter said this is an amazing rental This is an amazing rental This is an amazing rental A-D said he wants to rent this car We just asked This car 60,000 NTD per day 60,000 NTD per day And 600,000 NTD deposit Yeah Look at us Split up like this Each of us is about 10,000 NTD Not bad right? Not bad We'll just drive on the road And a bunch of girls will come Big G Big G for the scumbags This is our scumbag Can't open it Yeah, I can open it Big G for the scumbags Close it The sound of the candy This is what Joven taught me Joven the scumbag Look at this Let me introduce you to my car Bentley Wow Bentley series Big Bentley series Big Bentley series This one How is it? Is it nice? This is really a luxury area Yeah Let me introduce you to my car My car Aston Martin You guys have really nice cars That's not even the full piece Yeah? We don't have the Ferrari From the Lamborghini We'll just sneak up on that car Sneak up on it We'll drive and no one will come What a coincidence Look at this scumbag's view Yo They really got so short The whole world Got a bit shorter Look You're just suitable for this kind of car Peter With your muscles This is my car This is your car Super Li's car This should be called Big P Not Big G Big P He's even driving Wow The current situation is I used my credit card and my name to rent a car But it's with my brother's international driver's license So he's the driver But he later After the bridge Said no Must be paid by the driver With credit card So maybe he thinks If it's the driver What bag And if I run away He has no one to pay Maybe it's like this I'm going to get on that Bentley He just told us We can just go to MoMo Go see these cars Does MoMo include KaiKai? Should be ok We two are here Big delay The progress of the whole group This one is for you Don't say it's bad for you This one is for me This one is for you What is this one Bentley Wow Wow, this classic one Very beautiful The dashboard And his Clock Comfortable to sit Look at the whole face Simple design Go over I'm starving I have to get out of here I have to get out of here I just said I rent Audi Q Q8 or Q7 series It can be pressed down later So we can put our five luggage on it Ok, we're getting on This is our Q Is it Q7 or Q8 Sorry? Is this a Q7 or Q8 Q8 Q8, ok Look at this trunk It's actually two chairs here Can be pulled up The button is here Two more chairs But we put it all down So you can put your luggage in the back Alright Rent a car Now we are getting familiar with it We are going to pick up everyone Uh, yes Yes, it's the same as Google Maps This car is really comfortable A lot of space Then we will be back to the B&B After picking everyone up Drive all the way to Niujin It takes more than an hour About an hour and a half Then we will have a series of shooting in Niujin End Go to our last point Is a castle in the western part of the 16th century The last two days will be in the castle Almost died Applause to Peter I have been driving all the time Thank you Peter for driving for us We are going to the place where we return the car Peter thinks this time How about the British self-driving? I think driving is much more comfortable than Taiwan But the road here is smaller Yes, but the whole Everyone's The sense of compression is not so serious Because most of the time I drive in Taiwan There are too many cars Oh yes yes A bit dangerous feeling Then the car will not be so forgiving Yes, we seem to have not been pulled out in the UK Yes, not pulled out So I feel pretty comfortable Although sometimes it will be a bit small But I think it's more comfortable Compared with Taiwan What about driving? For you Because I went to Chongsheng last time Already married once I have already practiced So this time I have already got on very easily I understand We rented a car with Hertz last time Then we rented the car model is Audi Q8 It's just bigger in the back Actually, when I was studying at the beginning I just know there are five people Then five suitcases So I have found one I think the biggest SUV Because it's the kind of small truck that goes up Will be more expensive As a result, our position is still not enough It was later that Daqian wanted to hold his own suitcase We just took it off in front But it's okay The whole thing is quite big The back is quite big The ass is quite big I am used to it Then we rent a car like this for three days A total of 420,000 Taiwan dollars What 420,000 420,000 We will use four people to guess Because Peter's brother helped drive So brother and Alisha are a group It's okay So we will guess four people In this case, one person is about 10,000 yuan Equals three days But I think it's still quite cost-effective Because you think it's cost-effective You say our first day It's like we want We directly take a car from the city Then go to the one we want to go to Just next to Bristol Then on the way back We can also go to many Maybe there are no places where cars can't go Like Juizhen, Rome, Yuchang So I think it's pretty good overall Actually, I seriously feel What is compared to that horse car Are all the same So I just heard Although there is a scare But it seems to be a horse car Yes yes yes At this time, everyone should still I don't know what a horse car is Everyone continues to look down Just know what a horse car is Strange plate formation Ok so this is our experience So I recommend everyone If you can Just outside London Want to play some other towns You can rent a car in the London city center Then like us Come back to the airport on the last day Slow down So we don't have to go to Uber again Because it costs 100 yuan to go there Yes yes yes 200 like this So less than 100 is also a savings Yes pretty good Ok, for your reference Good Then continue to continue the RT daily I just today is our last day But I just put this The last clip I want to say that the rental car is a complete one So I will continue to follow the sun for several days Will continue to show everyone We are riding a car Where did you go to play? Bye bye\n" ] } ], "source": [ "print(Chinese_to_english[\"text\"]) #中文轉英文" ] }, { "cell_type": "markdown", "metadata": { "id": "XKMixQyW4QhC" }, "source": [ "# **語音輸入MP3檔案**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "l7yqyy1qbdmv" }, "outputs": [], "source": [ "!pip install sounddevice numpy lameenc" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "wtgb9Wl46wyq", "outputId": "3a075bd7-277d-426d-fda2-f32585d9a446" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading package lists... Done\n", "Building dependency tree... Done\n", "Reading state information... Done\n", "portaudio19-dev is already the newest version (19.6.0-1.1).\n", "0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.\n" ] } ], "source": [ "!apt-get install portaudio19-dev" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "hh6cb_W664qm", "outputId": "93642d16-838b-47e9-85dd-a3b36b8a2cfc" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pip in /usr/local/lib/python3.10/dist-packages (23.1.2)\n", "Collecting pip\n", " Downloading pip-23.3.1-py3-none-any.whl (2.1 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m13.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: pip\n", " Attempting uninstall: pip\n", " Found existing installation: pip 23.1.2\n", " Uninstalling pip-23.1.2:\n", " Successfully uninstalled pip-23.1.2\n", "Successfully installed pip-23.3.1\n" ] } ], "source": [ "!pip install --upgrade pip" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "DGI8C1bQ6-b0", "outputId": "489c9cc1-8bd2-4815-ce31-f9a56b1325db" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: cython in /usr/local/lib/python3.10/dist-packages (3.0.4)\n", "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip install cython" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "BTKWpfEJ6_2e", "outputId": "f860a86b-a6d3-4b3e-aa45-6ba841521832" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting pyaudio\n", " Downloading PyAudio-0.2.13.tar.gz (46 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.8/46.8 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", "Building wheels for collected packages: pyaudio\n", " Building wheel for pyaudio (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for pyaudio: filename=PyAudio-0.2.13-cp310-cp310-linux_x86_64.whl size=63861 sha256=f152caa1824f02c7e10a0e02f1533781033ce64dc665436f011c7bda3bce7e9d\n", " Stored in directory: /root/.cache/pip/wheels/14/f1/c2/d102b4765a82c5a7bb273998dca7e4a53fc58e9a1a516fda81\n", "Successfully built pyaudio\n", "Installing collected packages: pyaudio\n", "Successfully installed pyaudio-0.2.13\n", "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip install pyaudio" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "iDBdJxq50K3a", "outputId": "53901ff6-23b7-4cdd-d8e1-fb2d48a4bdd0" }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pyaudio\n", "p = pyaudio.PyAudio()\n", "p" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "id": "FOYzd_bZUOYZ", "outputId": "339daa34-27da-4565-9221-b6da06359c76" }, "outputs": [ { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" }, "text/plain": [ "'0.2.13'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pyaudio.__version__" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 381 }, "id": "88gbB1uv77BT", "outputId": "5eaa93e2-5218-4eae-9c04-b4991c163012" }, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "ignored", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpyaudio\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mthreading\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mwave\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pyaudio'", "", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n" ] } ], "source": [ "import pyaudio\n", "import time\n", "import threading\n", "import wave\n", "\n", "class Recorder():\n", " def __init__(self,chunk=1024,channels=1,rate=64000):\n", " self.CHUNK = chunk\n", " self.FORMAT = pyaudio.paInt16\n", " self.CHANNELS = channels\n", " self.RATE = rate\n", " self._running = True\n", " self._frames = []\n", " def start(self):\n", " threading._start_new_thread(self.__recording,())\n", " def __recording(self):\n", " self._running = True\n", " self._frames = []\n", " p = pyaudio.PyAudio()\n", " stream = p.open(format=self.FORMAT,channels=self.CHANNELS,rate=self.RATE,input=True,frames_per_buffer=self.CHUNK)\n", " while(self._running):\n", " data = stream.read(self.CHUNK)\n", " self._frames.append(data)\n", "\n", " stream.stop_stream()\n", " stream.close()\n", " p.terminate()\n", "\n", " def stop(self):\n", " self._running = False\n", "\n", " def save(self,filename):\n", "\n", " p = pyaudio.PyAudio()\n", " if not filename.endswith(\".wav\"):\n", " filename = filename + \".wav\"\n", " wf = wave.open(filename,'wb')\n", " wf.setnchannels(self.CHANNELS)\n", " wf.setsampwidth(p.get_sample_size(self.FORMAT))\n", " wf.setframerate(self.RATE)\n", " wf.writeframes(b''.join(self._frames))\n", " wf.close()\n", " print(\"Saved\")\n", "\n", "if __name__ == \"__main__\":\n", "\n", " for i in range(1,4):\n", " a = int(input('請輸入相應數字開始:'))\n", " if a == 1:\n", " rec = Recorder()\n", " begin = time.time()\n", " print(\"Start recording\")\n", " rec.start()\n", " b = int(input('請輸入相應數字停止:'))\n", " if b == 2:\n", " print(\"Stop recording\")\n", " rec.stop()\n", " fina = time.time()\n", " t = fina - begin\n", " print('錄音時間為%ds'%t)\n", " rec.save(\"1_%d.wav\"%i)\n" ] }, { "cell_type": "markdown", "metadata": { "id": "lNqb-16T7Tdi" }, "source": [ "# **從wav轉成MP3檔案**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 335 }, "id": "pZc-vIJI95gT", "outputId": "813aa148-d9b1-46a2-bd39-fe324fdcf388" }, "outputs": [ { "ename": "OSError", "evalue": "ignored", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpyaudio\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mpa\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpyaudio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPyAudio\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mpa\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_default_output_device_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/pyaudio/__init__.py\u001b[0m in \u001b[0;36mget_default_output_device_info\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 822\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0mrtype\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 823\u001b[0m \"\"\"\n\u001b[0;32m--> 824\u001b[0;31m \u001b[0mdevice_index\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpa\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_default_output_device\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 825\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_device_info_by_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevice_index\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 826\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mOSError\u001b[0m: No Default Output Device Available" ] } ], "source": [ "import pyaudio\n", "pa = pyaudio.PyAudio()\n", "pa.get_default_output_device_info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "_acE0NVc7no4", "outputId": "706862fb-d315-457a-9a70-2d8ac93ee89a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting pydub\n", " Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n", "Installing collected packages: pydub\n", "Successfully installed pydub-0.25.1\n", "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", "\u001b[0m" ] } ], "source": [ "!pip install pydub" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "dR5XxraszWOg" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 0 }