Adapt the project to use the bumble auracaster Reviewed-on: https://gitea.pstruebi.xyz/auracaster/multilang-translator-local/pulls/1
28 lines
863 B
Python
28 lines
863 B
Python
# resample .wav source to target sampling rate
|
|
import logging as log
|
|
import time
|
|
import os
|
|
import librosa
|
|
import soundfile as sf
|
|
|
|
|
|
def resample_file(filename, out_filename, target_rate=int(24e3)):
|
|
start=time.time()
|
|
# Load the original audio file
|
|
audio, rate = librosa.load(filename)
|
|
|
|
if rate == target_rate: # Nothing to do
|
|
sf.write(out_filename, audio, target_rate)
|
|
return
|
|
|
|
# Convert the sample rate to 24 kHz
|
|
resampled_audio = librosa.resample(audio, orig_sr=rate, target_sr=target_rate)
|
|
|
|
# Save the resampled audio as a new .wav file
|
|
sf.write(out_filename, resampled_audio, target_rate)
|
|
|
|
log.info("Resampling of %s took %s s", os.path.basename(filename), round(time.time() - start, 3))
|
|
|
|
if __name__ == "__main__":
|
|
resample_file('text_to_speech/welcome.wav', 'text_to_speech/welcome_resampled.wav')
|