use_bumble (#1)
Adapt the project to use the bumble auracaster Reviewed-on: https://gitea.pstruebi.xyz/auracaster/multilang-translator-local/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
27
multilang_translator/utils/resample.py
Normal file
27
multilang_translator/utils/resample.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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')
|
||||
Reference in New Issue
Block a user