mirror of
https://github.com/macaodha/batdetect2.git
synced 2025-06-29 14:41:58 +02:00
Added AudioPath as an alias for the path definition
This commit is contained in:
parent
52570738f2
commit
4282e2ae70
@ -99,6 +99,7 @@ consult the API documentation in the code.
|
|||||||
import warnings
|
import warnings
|
||||||
from typing import List, Optional, Tuple, BinaryIO, Any, Union
|
from typing import List, Optional, Tuple, BinaryIO, Any, Union
|
||||||
|
|
||||||
|
from .types import AudioPath
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
@ -244,9 +245,7 @@ def generate_spectrogram(
|
|||||||
|
|
||||||
|
|
||||||
def process_file(
|
def process_file(
|
||||||
path: Union[
|
path: AudioPath,
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
],
|
|
||||||
model: DetectionModel = MODEL,
|
model: DetectionModel = MODEL,
|
||||||
config: Optional[ProcessingConfiguration] = None,
|
config: Optional[ProcessingConfiguration] = None,
|
||||||
device: torch.device = DEVICE,
|
device: torch.device = DEVICE,
|
||||||
@ -256,9 +255,7 @@ def process_file(
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
path : Union[
|
path : AudioPath
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
]
|
|
||||||
Path to audio data.
|
Path to audio data.
|
||||||
model : DetectionModel, optional
|
model : DetectionModel, optional
|
||||||
Detection model. Uses default model if not specified.
|
Detection model. Uses default model if not specified.
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
"""Types used in the code base."""
|
"""Types used in the code base."""
|
||||||
|
|
||||||
from typing import List, NamedTuple, Optional, Union
|
from typing import List, NamedTuple, Optional, Union, Any, BinaryIO
|
||||||
|
|
||||||
|
import audioread
|
||||||
|
import os
|
||||||
|
import soundfile as sf
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
@ -40,6 +44,9 @@ __all__ = [
|
|||||||
"SpectrogramParameters",
|
"SpectrogramParameters",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
AudioPath = Union[
|
||||||
|
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
||||||
|
]
|
||||||
|
|
||||||
class SpectrogramParameters(TypedDict):
|
class SpectrogramParameters(TypedDict):
|
||||||
"""Parameters for generating spectrograms."""
|
"""Parameters for generating spectrograms."""
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import warnings
|
import warnings
|
||||||
from typing import Optional, Tuple, Union, Any, BinaryIO
|
from typing import Optional, Tuple, Union, Any, BinaryIO
|
||||||
|
|
||||||
|
from ..types import AudioPath
|
||||||
|
|
||||||
import librosa
|
import librosa
|
||||||
import librosa.core.spectrum
|
import librosa.core.spectrum
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -146,9 +148,7 @@ def generate_spectrogram(
|
|||||||
return spec, spec_for_viz
|
return spec, spec_for_viz
|
||||||
|
|
||||||
def load_audio(
|
def load_audio(
|
||||||
path: Union[
|
path: AudioPath,
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
],
|
|
||||||
time_exp_fact: float,
|
time_exp_fact: float,
|
||||||
target_samp_rate: int,
|
target_samp_rate: int,
|
||||||
scale: bool = False,
|
scale: bool = False,
|
||||||
@ -177,9 +177,7 @@ def load_audio(
|
|||||||
return sample_rate, audio_data
|
return sample_rate, audio_data
|
||||||
|
|
||||||
def load_audio_and_samplerate(
|
def load_audio_and_samplerate(
|
||||||
path: Union[
|
path: AudioPath,
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
],
|
|
||||||
time_exp_fact: float,
|
time_exp_fact: float,
|
||||||
target_samp_rate: int,
|
target_samp_rate: int,
|
||||||
scale: bool = False,
|
scale: bool = False,
|
||||||
|
@ -2,6 +2,8 @@ import json
|
|||||||
import os
|
import os
|
||||||
from typing import Any, Iterator, List, Optional, Tuple, Union, BinaryIO
|
from typing import Any, Iterator, List, Optional, Tuple, Union, BinaryIO
|
||||||
|
|
||||||
|
from ..types import AudioPath
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import torch
|
import torch
|
||||||
@ -735,9 +737,7 @@ def process_audio_array(
|
|||||||
|
|
||||||
|
|
||||||
def process_file(
|
def process_file(
|
||||||
path: Union[
|
path: AudioPath,
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
],
|
|
||||||
model: DetectionModel,
|
model: DetectionModel,
|
||||||
config: ProcessingConfiguration,
|
config: ProcessingConfiguration,
|
||||||
device: torch.device,
|
device: torch.device,
|
||||||
@ -750,7 +750,7 @@ def process_file(
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
path : str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
path : AudioPath
|
||||||
Path to audio file.
|
Path to audio file.
|
||||||
|
|
||||||
model : torch.nn.Module
|
model : torch.nn.Module
|
||||||
@ -760,7 +760,7 @@ def process_file(
|
|||||||
Configuration for processing.
|
Configuration for processing.
|
||||||
|
|
||||||
file_id: Optional[str],
|
file_id: Optional[str],
|
||||||
Give the data an id. Defaults to the filename if path is a string. Otherwise
|
Give the data an id. Defaults to the filename if path is a string. Otherwise an md5 will be calculated from the binary data.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -859,9 +859,7 @@ def process_file(
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _generate_id(path: Union[
|
def _generate_id(path: AudioPath) -> str:
|
||||||
str, int, os.PathLike[Any], sf.SoundFile, audioread.AudioFile, BinaryIO
|
|
||||||
]) -> str:
|
|
||||||
""" Generate an id based on the path.
|
""" Generate an id based on the path.
|
||||||
|
|
||||||
If the path is a str or PathLike it will parsed as the basename.
|
If the path is a str or PathLike it will parsed as the basename.
|
||||||
|
Loading…
Reference in New Issue
Block a user