1 Answer. 1 year late but try using a buffer to keep the audio bytes in memory. from pydub import AudioSegment import speech_recognition as sr import io r = sr.Recognizer () for i in range (5): audio = AudioSegment.from_wav ("some_wav.wav") audio_chunk = audio [int (i*1000):int (i*3000)] buffer = io.BytesIO () audio_chunk.export (buffer, format I want to keep my project as lightweight as possible without needing to add 200 meabytes of data just for video to audio conversion which is just a very small part of the project. So is there any way to . not use ffmpeg ; use another lightweight converter with a python wrapper The first step in audio manipulation is loading a sound file, and being able to play it. In order to load an audio file using pydub, we will use the AudioSegment class we imported in the previous step. audio = AudioSegment.from_file("countdown.mp3", format="mp3") Playing audio is a little bit trickier, as pydub is an audio manipulation library Line 3-8: Defining Our Function. def mp4tomp3 (mp4file,mp3file): videoclip=VideoFileClip (mp4file) audioclip=videoclip.audio audioclip.write_audiofile (mp3file) audioclip.close () videoclip.close () Here we define a function which takes in two arguments : mp4file: which contains the name of the mp4 file we want to convert. Seems the only way here is to use ffmpeg but idk how to achieve it. i made the script to take an input of mp3 folder and one .png photo`. then it's will create new folder x-converted where i would like to convert each mp3 to mp4 with the static png with same name such as file1.mp3 to became file1.mp4. import os import sys from pathlib import Simple python script to convert m4b audio books to a group of mp3 files split by chapter. - GitHub - valekhz/m4b-converter: Simple python script to convert m4b audio books to a group of mp3 files split by chapter. vbORWf. mkdir pytranscribe cd pytranscribe. We also need to export our AssemblyAI API key as an environment variable. Sign up for an AssemblyAI account and log in to the AssemblyAI dashboard, then copy "Your API token" as shown in this screenshot: export ASSEMBLYAI_KEY =your-api-key-here. In this tutorial, we are going to see how to convert Mp4 to Mp3 files using Python. This task can be easily done using the moviepy library from Python. First, install the moviepy library. pip install moviepy. Now import the required functions from the library. from moviepy.editor import VideoFileClip,AudioFileClip. Speech recognition only supports WAV file format. This is a processing function that uses speech_recognition and pydub to convert MP3 into WAV then to TEXT using Google's Speech API. It chunks the MP3 file into 60s portions to fit inside google's limits and will allow you to run about 50 minutes of audio in a day. Line 3-8: Defining Our Function. def mp4tomp3 (mp4file,mp3file): videoclip=VideoFileClip (mp4file) audioclip=videoclip.audio audioclip.write_audiofile (mp3file) audioclip.close () videoclip.close () Here we define a function which takes in two arguments : mp4file: which contains the name of the mp4 file we want to convert. Sorted by: 113. kdazzle's solution is almost there - it still output a stereo wav, here is a slightly modified version that generate mono: ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav. also, if this is for pre-processing speech data for sphinx 4 see here: Convert audio files for CMU Sphinx 4 input. Share.

convert wav to mp3 python