write a script to convert an mp3 audio file to a wav format with 16 kHz sampling rate
- User
write a script to convert an mp3 audio file to a wav format with 16 kHz sampling rate
Assistant
import os import subprocess # Define the input MP3 file path input_mp3_file = 'path/to/input.mp3' # Define the output WAV file path output_wav_file = 'path/to/output.wav' # Define the sampling rate for the output WAV file sampling_rate = 16000 # Check if the input MP3 file exists if not os.path.isfile(input_mp3_file): print("Error: Input MP3 file not found.") exit() # Check if the output WAV file already exists if os.path.isfile(output_wav_file): print("Error: Output WAV file already exists.") exit() # Convert the MP3 file to WAV using ffmpeg command = ['ffmpeg', '-i', input_mp3_file, '-ar', str(sampling_rate), output_wav_file] # Execute the ffmpeg command subprocess.call(command) # Check if the output WAV file was created successfully if os.path.isfile(output_wav_file): print("MP3 file converted to WAV successfully.") else: print("Error: Failed to convert MP3 file to WAV.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.