Skip to content

Commit

Permalink
needs to be float type for load to work
Browse files Browse the repository at this point in the history
  • Loading branch information
lauras5 committed Sep 12, 2023
1 parent 9b86d06 commit eb5733f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/data
/logs
src/paths.py

# Python
__pycache__/
Expand Down
3 changes: 2 additions & 1 deletion src/capture_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import sys

from paths import AUDIO_PATH
from logging_config import logger

# duration in seconds
Expand Down Expand Up @@ -47,5 +48,5 @@ def capture_audio_to_file(output_file, duration=5, sample_rate=44100, channels=1
# test
if __name__ == "__main__":
timestr = time.strftime("%Y%m%d_%H%M")
out_filename = f"../data/audio_samples/recorded_audio_{timestr}.wav"
out_filename = f"{AUDIO_PATH}/recorded_audio_{timestr}.wav"
capture_audio_to_file(out_filename, duration=5)
3 changes: 2 additions & 1 deletion src/logging_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import sys
import traceback
from paths import DIR_PATH

logging.basicConfig(
filename='./logs/error.log',
filename=f'{DIR_PATH}logs/error.log',
level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(message)s'
)
Expand Down
8 changes: 4 additions & 4 deletions src/process_audio.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import librosa
import librosa.display
import numpy as np
import matplotlib.pyplot as plt
from logging_config import logger

from paths import AUDIO_PATH

def process_audio_file(audio_file):
try:
# Load the audio file
y, sr = librosa.load(audio_file)

y, sr = librosa.load(audio_file, dtype=np.float32)
# Extract audio features (e.g., MFCCs)
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=40)

Expand All @@ -32,5 +32,5 @@ def process_audio_file(audio_file):


if __name__ == "__main__":
recorded_audio_file = "../data/audio_samples/recorded_audio_20230911_1655.wav"
recorded_audio_file = f"{AUDIO_PATH}recorded_audio_20230911_1655.wav"
process_audio_file(recorded_audio_file)

0 comments on commit eb5733f

Please sign in to comment.