Skip to content

Commit

Permalink
Read audio from minio storage
Browse files Browse the repository at this point in the history
  • Loading branch information
csaudiodesign committed Dec 4, 2023
1 parent bea3c36 commit 7e57d28
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion batdetect2_gui/audio_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import warnings
import io

import numpy as np
from PIL import Image

import wavfile
from minio import Minio

import credentials as crd

s3 = Minio(
crd.minio.host,
access_key=crd.minio.access_key,
secret_key=crd.minio.secret_key,
)

def generate_spectrogram(audio, sampling_rate, params):
"""Creates an spectrogram image
Expand Down Expand Up @@ -69,7 +78,9 @@ def load_audio_file(audio_file, time_exp_fact):
"""
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=wavfile.WavFileWarning)
sampling_rate, audio_raw = wavfile.read(audio_file)
response = s3.get_object(crd.minio.bucket, audio_file)
bytes_buffer = io.BytesIO(response.read())
sampling_rate, audio_raw = wavfile.read(bytes_buffer)
assert len(audio_raw.shape) == 1 # throw error if there is a stereo file
sampling_rate = sampling_rate * time_exp_fact
return sampling_rate, audio_raw
Expand Down

0 comments on commit 7e57d28

Please sign in to comment.