-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_purifier.py
29 lines (22 loc) · 1 KB
/
audio_purifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pydub import AudioSegment
from pydub.playback import play
import simpleaudio as sa
import os
def convert_audio(input_file, output_file, sample_rate):
audio = AudioSegment.from_file(input_file)
# Resample the audio to the desired sample rate (e.g., 16000 Hz)
audio = audio.set_frame_rate(sample_rate)
# Export the audio to WAV format
audio.export(output_file, format="wav")
return output_file
def Purify_Audio():
input_file = "./audios/temp.wav" # Replace with your input audio file path
output_file = "./audios/input.wav" # Replace with the desired output file path
sample_rate = 16000 # Change to 8000 if needed
if not os.path.exists(input_file):
print(f"Input file '{input_file}' not found.")
else:
converted_file = convert_audio(input_file, output_file, sample_rate)
print(f"Audio file converted and saved to '{converted_file}'.")
# Play the converted audio (optional)
wave_obj = sa.WaveObject.from_wave_file(converted_file)