From c737e7759ef27f1d1f22b85326b848d890ab540e Mon Sep 17 00:00:00 2001 From: YellowFoxH4XOR Date: Sun, 15 Oct 2023 06:30:01 +0200 Subject: [PATCH] fix: Added generic ffmpeg package helper and updated sample wav file --- ...on_Convert_audiofile_from_wav_to_mp3.ipynb | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/Python/Python_Convert_audiofile_from_wav_to_mp3.ipynb b/Python/Python_Convert_audiofile_from_wav_to_mp3.ipynb index d727af2ee6..ae99a8f5a2 100644 --- a/Python/Python_Convert_audiofile_from_wav_to_mp3.ipynb +++ b/Python/Python_Convert_audiofile_from_wav_to_mp3.ipynb @@ -100,31 +100,64 @@ "outputs": [], "source": [ "!wget \"https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz\"\n", - "!tar xf ffmpeg-git-amd64-static.tar.xz\n", - "!mv ffmpeg-git-20230313-amd64-static ffmpeg" + "!tar xf ffmpeg-git-amd64-static.tar.xz" ] }, { "cell_type": "code", "execution_count": null, - "id": "de44748f-c70f-4a9e-ac11-c183b79d4b94", + "id": "568e293d-8bcd-4806-bc4c-c49f826055ec", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def find_directory_starting_with_ffmpeg_git():\n", + " # Get the current directory\n", + " current_directory = os.getcwd()\n", + "\n", + " # List all directories in the current directory\n", + " directories = [d for d in os.listdir(current_directory) if os.path.isdir(os.path.join(current_directory, d))]\n", + "\n", + " # Check for directories starting with \"ffmpeg-git\"\n", + " matching_directories = [d for d in directories if d.startswith(\"ffmpeg-git\")]\n", + " return matching_directories\n", + "\n", + "dir_path = find_directory_starting_with_ffmpeg_git()\n", + "package_name = None\n", + "if len(dir_path) > 1:\n", + " print(\"Multiple ffmpeg directory found using the first one\")\n", + "package_name = dir_path[0]\n", + "mv_package = f\"mv {package_name} ffmpeg\"\n", + "!rm -rf ffmpeg\n", + "!{mv_package}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3f0b9f9-552a-4298-91f5-2dbc43172163", "metadata": { - "papermill": {}, "tags": [] }, "outputs": [], "source": [ "import os\n", "new_path = os.path.join(os.getcwd(), \"ffmpeg\")\n", - "%env PATH=$new_path" + "os.environ['PATH'] += os.pathsep + new_path" ] }, { "cell_type": "markdown", - "id": "a808cf8b-c61c-4651-86c4-8be456c79b53", + "id": "924ae217-e8c9-4543-80e5-ca0accf3c7f4", "metadata": { - "papermill": {}, - "tags": [] + "execution": { + "iopub.execute_input": "2023-10-15T03:37:08.099633Z", + "iopub.status.busy": "2023-10-15T03:37:08.099401Z", + "iopub.status.idle": "2023-10-15T03:37:08.102882Z", + "shell.execute_reply": "2023-10-15T03:37:08.101924Z", + "shell.execute_reply.started": "2023-10-15T03:37:08.099606Z" + } }, "source": [ "### Import libraries" @@ -133,16 +166,15 @@ { "cell_type": "code", "execution_count": null, - "id": "2ff36cda-6873-4cf5-aa6c-eeb499b250d8", + "id": "0d743d71-e781-469d-bbf0-78b168ead9c8", "metadata": { - "papermill": {}, "tags": [] }, "outputs": [], "source": [ "try:\n", " from pydub import AudioSegment\n", - "except:\n", + "except Exception:\n", " !pip install pydub\n", " from pydub import AudioSegment\n", "import requests" @@ -172,7 +204,7 @@ "source": [ "# Inputs\n", "## link of sample wav file\n", - "audio_file_url = 'https://file-examples.com/storage/fef1706276640fa2f99a5a4/2017/11/file_example_WAV_1MG.wav'\n", + "audio_file_url = 'https://www2.cs.uic.edu/~i101/SoundFiles/BabyElephantWalk60.wav'\n", "wav_path = 'audio.wav'\n", "\n", "##Output\n", @@ -320,4 +352,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}