{"id":13396962,"url":"https://github.com/jiaaro/pydub","last_synced_at":"2025-05-13T00:27:54.489Z","repository":{"id":1457918,"uuid":"1692604","full_name":"jiaaro/pydub","owner":"jiaaro","description":"Manipulate audio with a simple and easy high level interface","archived":false,"fork":false,"pushed_at":"2024-07-25T08:47:51.000Z","size":36944,"stargazers_count":9144,"open_issues_count":379,"forks_count":1065,"subscribers_count":135,"default_branch":"master","last_synced_at":"2025-01-31T09:22:55.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://pydub.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jiaaro.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-05-02T18:42:38.000Z","updated_at":"2025-01-31T07:04:35.000Z","dependencies_parsed_at":"2023-07-05T18:31:17.063Z","dependency_job_id":"7771e275-9062-4341-9bca-e1076c395a2f","html_url":"https://github.com/jiaaro/pydub","commit_stats":{"total_commits":606,"total_committers":98,"mean_commits":6.183673469387755,"dds":0.759075907590759,"last_synced_commit":"996cec42e9621701edb83354232b2c0ca0121560"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiaaro%2Fpydub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiaaro%2Fpydub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiaaro%2Fpydub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jiaaro%2Fpydub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jiaaro","download_url":"https://codeload.github.com/jiaaro/pydub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250494416,"owners_count":21439985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:08.470Z","updated_at":"2025-04-23T18:44:16.593Z","avatar_url":"https://github.com/jiaaro.png","language":"Python","funding_links":[],"categories":["Audio","Python","资源列表","音频处理","Media","Data Processing","音频","Tooling \u0026 Infrastructure","Audio Processing \u0026 I/O","Audio [🔝](#readme)","📚 فهرست","Read / Write / Metadata","Software","Audio Processing","Awesome Python","Feature Extraction","Developing"],"sub_categories":["音频","Audio Processing","Data Pre-processing \u0026 Loading","Frameworks \u0026 SDKs","کار با فایل های صوتی","IO router / deconstructed loops anchor","Video","Mobile Applications","Audio","Drone Frames","Software"],"readme":"# Pydub [![Build Status](https://travis-ci.org/jiaaro/pydub.svg?branch=master)](https://travis-ci.org/jiaaro/pydub) [![Build status](https://ci.appveyor.com/api/projects/status/gy1ucp9o5khq7fqi/branch/master?svg=true)](https://ci.appveyor.com/project/jiaaro/pydub/branch/master)\n\nPydub lets you do stuff to audio in a way that isn't stupid.\n\n**Stuff you might be looking for**:\n - [Installing Pydub](https://github.com/jiaaro/pydub#installation)\n - [API Documentation](https://github.com/jiaaro/pydub/blob/master/API.markdown)\n - [Dependencies](https://github.com/jiaaro/pydub#dependencies)\n - [Playback](https://github.com/jiaaro/pydub#playback)\n - [Setting up ffmpeg](https://github.com/jiaaro/pydub#getting-ffmpeg-set-up)\n - [Questions/Bugs](https://github.com/jiaaro/pydub#bugs--questions)\n \n\n##  Quickstart\n\nOpen a WAV file\n\n```python\nfrom pydub import AudioSegment\n\nsong = AudioSegment.from_wav(\"never_gonna_give_you_up.wav\")\n```\n\n...or a mp3\n\n```python\nsong = AudioSegment.from_mp3(\"never_gonna_give_you_up.mp3\")\n```\n\n... or an ogg, or flv, or [anything else ffmpeg supports](http://www.ffmpeg.org/general.html#File-Formats)\n\n```python\nogg_version = AudioSegment.from_ogg(\"never_gonna_give_you_up.ogg\")\nflv_version = AudioSegment.from_flv(\"never_gonna_give_you_up.flv\")\n\nmp4_version = AudioSegment.from_file(\"never_gonna_give_you_up.mp4\", \"mp4\")\nwma_version = AudioSegment.from_file(\"never_gonna_give_you_up.wma\", \"wma\")\naac_version = AudioSegment.from_file(\"never_gonna_give_you_up.aiff\", \"aac\")\n```\n\nSlice audio:\n\n```python\n# pydub does things in milliseconds\nten_seconds = 10 * 1000\n\nfirst_10_seconds = song[:ten_seconds]\n\nlast_5_seconds = song[-5000:]\n```\n\nMake the beginning louder and the end quieter\n\n```python\n# boost volume by 6dB\nbeginning = first_10_seconds + 6\n\n# reduce volume by 3dB\nend = last_5_seconds - 3\n```\n\nConcatenate audio (add one file to the end of another)\n\n```python\nwithout_the_middle = beginning + end\n```\n\nHow long is it?\n\n```python\nwithout_the_middle.duration_seconds == 15.0\n```\n\nAudioSegments are immutable\n\n```python\n# song is not modified\nbackwards = song.reverse()\n```\n\nCrossfade (again, beginning and end are not modified)\n\n```python\n# 1.5 second crossfade\nwith_style = beginning.append(end, crossfade=1500)\n```\n\nRepeat\n\n```python\n# repeat the clip twice\ndo_it_over = with_style * 2\n```\n\nFade (note that you can chain operations because everything returns\nan AudioSegment)\n\n```python\n# 2 sec fade in, 3 sec fade out\nawesome = do_it_over.fade_in(2000).fade_out(3000)\n```\n\nSave the results (again whatever ffmpeg supports)\n\n```python\nawesome.export(\"mashup.mp3\", format=\"mp3\")\n```\n\nSave the results with tags (metadata)\n\n```python\nawesome.export(\"mashup.mp3\", format=\"mp3\", tags={'artist': 'Various artists', 'album': 'Best of 2011', 'comments': 'This album is awesome!'})\n```\n\nYou can pass an optional bitrate argument to export using any syntax ffmpeg \nsupports.\n\n```python\nawesome.export(\"mashup.mp3\", format=\"mp3\", bitrate=\"192k\")\n```\n\nAny further arguments supported by ffmpeg can be passed as a list in a \n'parameters' argument, with switch first, argument second. Note that no \nvalidation takes place on these parameters, and you may be limited by what \nyour particular build of ffmpeg/avlib supports.\n\n```python\n# Use preset mp3 quality 0 (equivalent to lame V0)\nawesome.export(\"mashup.mp3\", format=\"mp3\", parameters=[\"-q:a\", \"0\"])\n\n# Mix down to two channels and set hard output volume\nawesome.export(\"mashup.mp3\", format=\"mp3\", parameters=[\"-ac\", \"2\", \"-vol\", \"150\"])\n```\n\n## Debugging\n\nMost issues people run into are related to converting between formats using\nffmpeg/avlib. Pydub provides a logger that outputs the subprocess calls to \nhelp you track down issues:\n\n```python\n\u003e\u003e\u003e import logging\n\n\u003e\u003e\u003e l = logging.getLogger(\"pydub.converter\")\n\u003e\u003e\u003e l.setLevel(logging.DEBUG)\n\u003e\u003e\u003e l.addHandler(logging.StreamHandler())\n\n\u003e\u003e\u003e AudioSegment.from_file(\"./test/data/test1.mp3\")\nsubprocess.call(['ffmpeg', '-y', '-i', '/var/folders/71/42k8g72x4pq09tfp920d033r0000gn/T/tmpeZTgMy', '-vn', '-f', 'wav', '/var/folders/71/42k8g72x4pq09tfp920d033r0000gn/T/tmpK5aLcZ'])\n\u003cpydub.audio_segment.AudioSegment object at 0x101b43e10\u003e\n```\n\nDon't worry about the temporary files used in the conversion. They're cleaned up \nautomatically.\n\n## Bugs \u0026 Questions\n\nYou can file bugs in our [github issues tracker](https://github.com/jiaaro/pydub/issues), \nand ask any technical questions on \n[Stack Overflow using the pydub tag](http://stackoverflow.com/questions/ask?tags=pydub). \nWe keep an eye on both.\n\n## Installation\n\nInstalling pydub is easy, but don't forget to install ffmpeg/avlib (the next section in this doc)\n\n    pip install pydub\n\nOr install the latest dev version from github (or replace `@master` with a [release version like `@v0.12.0`](https://github.com/jiaaro/pydub/releases))…\n\n    pip install git+https://github.com/jiaaro/pydub.git@master\n\n-OR-\n\n    git clone https://github.com/jiaaro/pydub.git\n\n-OR-\n\nCopy the pydub directory into your python path. Zip \n[here](https://github.com/jiaaro/pydub/zipball/master)\n\n## Dependencies\n\nYou can open and save WAV files with pure python. For opening and saving non-wav \nfiles – like mp3 – you'll need [ffmpeg](http://www.ffmpeg.org/) or \n[libav](http://libav.org/).\n\n### Playback\n\nYou can play audio if you have one of these installed (simpleaudio _strongly_ recommended, even if you are installing ffmpeg/libav):\n\n - [simpleaudio](https://simpleaudio.readthedocs.io/en/latest/)\n - [pyaudio](https://people.csail.mit.edu/hubert/pyaudio/docs/#)\n - ffplay (usually bundled with ffmpeg, see the next section)\n - avplay (usually bundled with libav, see the next section)\n \n```python\nfrom pydub import AudioSegment\nfrom pydub.playback import play\n\nsound = AudioSegment.from_file(\"mysound.wav\", format=\"wav\")\nplay(sound)\n```\n\n## Getting ffmpeg set up\n\nYou may use **libav or ffmpeg**.\n\nMac (using [homebrew](http://brew.sh)):\n\n```bash\n# libav\nbrew install libav\n\n####    OR    #####\n\n# ffmpeg\nbrew install ffmpeg\n```\n\nLinux (using aptitude):\n\n```bash\n# libav\napt-get install libav-tools libavcodec-extra\n\n####    OR    #####\n\n# ffmpeg\napt-get install ffmpeg libavcodec-extra\n```\n\nWindows:\n\n1. Download and extract libav from [Windows binaries provided here](http://builds.libav.org/windows/).\n2. Add the libav `/bin` folder to your PATH envvar\n3. `pip install pydub`\n\n## Important Notes\n\n`AudioSegment` objects are [immutable](http://www.devshed.com/c/a/Python/String-and-List-Python-Object-Types/1/)\n\n\n### Ogg exporting and default codecs\n\nThe Ogg specification ([http://tools.ietf.org/html/rfc5334](rfc5334)) does not specify\nthe codec to use, this choice is left up to the user. Vorbis and Theora are just\nsome of a number of potential codecs (see page 3 of the rfc) that can be used for the\nencapsulated data.\n\nWhen no codec is specified exporting to `ogg` will _default_ to using `vorbis`\nas a convenience. That is:\n\n```python\nfrom pydub import AudioSegment\nsong = AudioSegment.from_mp3(\"test/data/test1.mp3\")\nsong.export(\"out.ogg\", format=\"ogg\")  # Is the same as:\nsong.export(\"out.ogg\", format=\"ogg\", codec=\"libvorbis\")\n```\n\n## Example Use\n\nSuppose you have a directory filled with *mp4* and *flv* videos and you want to convert all of them to *mp3* so you can listen to  them on your mp3 player.\n\n```python\nimport os\nimport glob\nfrom pydub import AudioSegment\n\nvideo_dir = '/home/johndoe/downloaded_videos/'  # Path where the videos are located\nextension_list = ('*.mp4', '*.flv')\n\nos.chdir(video_dir)\nfor extension in extension_list:\n    for video in glob.glob(extension):\n        mp3_filename = os.path.splitext(os.path.basename(video))[0] + '.mp3'\n        AudioSegment.from_file(video).export(mp3_filename, format='mp3')\n```\n\n### How about another example?\n\n```python\nfrom glob import glob\nfrom pydub import AudioSegment\n\nplaylist_songs = [AudioSegment.from_mp3(mp3_file) for mp3_file in glob(\"*.mp3\")]\n\nfirst_song = playlist_songs.pop(0)\n\n# let's just include the first 30 seconds of the first song (slicing\n# is done by milliseconds)\nbeginning_of_song = first_song[:30*1000]\n\nplaylist = beginning_of_song\nfor song in playlist_songs:\n\n    # We don't want an abrupt stop at the end, so let's do a 10 second crossfades\n    playlist = playlist.append(song, crossfade=(10 * 1000))\n\n# let's fade out the end of the last song\nplaylist = playlist.fade_out(30)\n\n# hmm I wonder how long it is... ( len(audio_segment) returns milliseconds )\nplaylist_length = len(playlist) / (1000*60)\n\n# lets save it!\nwith open(\"%s_minute_playlist.mp3\" % playlist_length, 'wb') as out_f:\n    playlist.export(out_f, format='mp3')\n```\n\n## License ([MIT License](http://opensource.org/licenses/mit-license.php))\n\nCopyright © 2011 James Robert, http://jiaaro.com\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiaaro%2Fpydub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjiaaro%2Fpydub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjiaaro%2Fpydub/lists"}