Skip to content

Commit

Permalink
fix: Added generic ffmpeg package helper and updated sample wav file
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowFoxH4XOR committed Oct 15, 2023
1 parent c899096 commit c737e77
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions Python/Python_Convert_audiofile_from_wav_to_mp3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -320,4 +352,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit c737e77

Please sign in to comment.