Skip to content

Commit

Permalink
improve annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalt committed Aug 26, 2022
1 parent fa97804 commit b7c36da
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions rawdata/code/preproc/081-align_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging
from dataclasses import dataclass, field
from typing import List
from typing import List, Tuple

import hydra
import librosa as lb # type: ignore
Expand All @@ -18,6 +18,7 @@
import soundfile as sf # type: ignore
from hydra.core.config_store import ConfigStore
from librosa import display

from utils import BaseConfig, prepare_script

logger = logging.getLogger(__file__)
Expand Down Expand Up @@ -105,19 +106,19 @@ def align_audio(audio: np.ndarray, shift: int, target_duration: int) -> np.ndarr
return audio[:target_duration]


def read_meg_audio(raw_path: str, audio_ch):
def read_meg_audio(raw_path: str, audio_ch: str) -> Tuple[np.ndarray, int]:
raw = mne.io.read_raw_fif(raw_path, preload=True)
audio_meg = np.squeeze(raw.get_data(picks=audio_ch, reject_by_annotation=None))
sr_meg = raw.info["sfreq"]
return audio_meg, sr_meg
return audio_meg, int(sr_meg)


def resample(nsamples: int, sr_from: float, sr_to: float) -> int:
return int(nsamples / sr_from * sr_to)


@hydra.main(config_path="../configs/", config_name="081-align_audio")
def main(cfg: Config):
def main(cfg: Config) -> None:
prepare_script(logger, script_name=__file__)

audio_meg, sr_meg = read_meg_audio(cfg.input.raw, cfg.audio_ch)
Expand Down

0 comments on commit b7c36da

Please sign in to comment.