How to convert from WAV to MP3 for free: Script to achieve it easily in Python.

Introduction: Inconveniences and Challenges of Conversion Free Software

WAV is a high-quality uncompressed audio format often used in music production and professional recording. However, as is, the file size is very large, making it inefficient to store and share. For this reason, many people want to convert WAV files to MP3 format.

Situations where you want to “convert WAV to MP3.”

  • want to easily manage high quality audio from recordings and interviews

    When you want to convert interview or recording data saved in WAV format to MP3 for efficient organization.

  • to reduce file size for online distribution

    When you want to upload WAV audio in MP3 format for use in podcasts or music distribution for comfortable streaming and downloading.

  • Polylang placeholder do not modify to make
    it easier to share audio files

However, when using many free sites, you may face the following problems

Claiming to be “free” but leading you to a paid plan
In many cases, even if the conversion appears to be free at first, there is a capacity limit or a limit on the number of times the conversion can be performed, and “billing required” is indicated in the middle of the conversion.

Multiple files cannot be converted in batches and must be uploaded manually one file at a time.
Many free online tools allow only one file at a time to be uploaded, so when multiple files are to be converted, the process of uploading, converting, and downloading must be repeated.

To solve these problems, I will show you how to quickly convert WAV to MP3 on your own computer using a simple script in Python.

WAV to MP3 conversion script using Python

To solve these inconveniences, Python scripts can be used to efficiently convert WAV files to MP3 for free. Below is a batch conversion script using Python.

Required Preparation

First, install Pydub, the required library. Execute the following command

pip install pydub

Pydub also requires ffmpeg, an audio processing library. Install ffmpeg with the following command (example using Homebrew).

Mac:.

brew install ffmpeg

Windows: Windows

Download the installer from the official ffmpeg website and pass it through.

WAV to MP3 conversion script example

The following script allows you to batch convert WAV files in a specified directory to MP3. The paths are set up in a generic way so that anyone can easily modify them to suit their own environment.

from pydub import AudioSegment
import os

# WAVファイルが保存されているディレクトリ
wav_directory = "./input_wav"

# MP3ファイルを保存するディレクトリ
mp3_directory = "./output_mp3"

# 出力ディレクトリが存在しない場合は作成
os.makedirs(mp3_directory, exist_ok=True)

# 指定ディレクトリ内のすべてのWAVファイルを取得
wav_files = [f for f in os.listdir(wav_directory) if f.endswith('.wav')]

for wav_file in wav_files:
    # WAVファイルを読み込み
    audio = AudioSegment.from_file(os.path.join(wav_directory, wav_file), format="wav")

    # サンプルレートを20KHzに変更(必要に応じて調整可能)
    audio = audio.set_frame_rate(20000)

    # MP3として保存
    audio.export(os.path.join(mp3_directory, wav_file.replace('.wav', '.mp3')), format="mp3")

print("変換が完了しました!")

How to use Python scripts

  1. Save the WAV file you want to convert in the WAVfile directory: wav_directory (e.g. ./input_wav ).
  2. Save the converted MP3 file to: mp3_directory (e.g. ./output_mp3 ).
  3. Run the script: Running the above code in Python will convert all specified WAV files to MP3 and save them in the specified folder.

Benefits of Python Scripting

  1. Free

    You can use it without any restrictions and without having to rely on online services.

  2. Multiple files can be converted at once

    All WAV files in a folder can be converted at once, saving you time and effort.

  3. Free to adjust voice quality

    Sample rate and bit rate can be adjusted as needed to optimize audio quality.

  4. Polylang placeholder
    available offline
    do not modify

Click here for an article on “How to compress for free: a script to easily achieve this in Python “.

If you want to transcribe audio files, “Interview AI” is recommended.

If, after converting to MP3 audio files, you would like to further transcribe them, Interview AI is recommended.

With Interview AI, an hour-long audio file can be transcribed in just 15 seconds and automatically corrected to a natural conversational format.

If you need to transcribe a long audio file, we encourage you to try Interview AI for free.

summary

Converting WAVs to MP3s can be used in a variety of situations to reduce file size and make them easier to share and play. Instead of relying on online free sites, you can use Python scripts for free batch conversion.

Manage your audio data more efficiently, freeing you from the tedious conversion process!

Copied title and URL