mistral_common.audio
Audio(audio_array, sampling_rate, format)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_array
|
ndarray
|
The audio data as a numpy array. |
required |
sampling_rate
|
int
|
The sampling rate of the audio in Hz. |
required |
format
|
str
|
The format of the audio file. |
required |
Source code in src/mistral_common/audio.py
duration
property
Calculate the duration of the audio in seconds.
Returns:
Type | Description |
---|---|
float
|
The duration of the audio in seconds. |
from_base64(audio_base64, strict=True)
staticmethod
Create an Audio instance from a base64 encoded string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_base64
|
str
|
The base64 encoded audio data. |
required |
strict
|
bool
|
Whether to strictly enforce mono audio. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Audio
|
An instance of the Audio class. |
Source code in src/mistral_common/audio.py
from_bytes(audio_bytes, strict=True)
staticmethod
Create an Audio instance from bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_bytes
|
bytes
|
The audio data as bytes. |
required |
strict
|
bool
|
Whether to strictly enforce mono audio. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Audio
|
An instance of the Audio class. |
Source code in src/mistral_common/audio.py
from_file(file, strict=True)
staticmethod
Create an Audio instance from an audio file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str
|
Path to the audio file. |
required |
strict
|
bool
|
Whether to strictly enforce mono audio. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Audio
|
An instance of the Audio class. |
Source code in src/mistral_common/audio.py
from_raw_audio(audio)
staticmethod
Create an Audio instance from a RawAudio object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio
|
RawAudio
|
The RawAudio object containing audio data. |
required |
Returns:
Type | Description |
---|---|
Audio
|
An instance of the Audio class. |
Source code in src/mistral_common/audio.py
from_url(url, strict=True)
staticmethod
Create an Audio instance from a URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the audio file. |
required |
strict
|
bool
|
Whether to strictly enforce mono audio. |
True
|
Returns:
Type | Description |
---|---|
Audio
|
An instance of the Audio class. |
Source code in src/mistral_common/audio.py
resample(new_sampling_rate)
Resample audio data to a new sampling rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_sampling_rate
|
int
|
The new sampling rate to resample the audio to. |
required |
Source code in src/mistral_common/audio.py
to_base64(format, prefix=False)
Convert the audio data to a base64 encoded string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The format to encode the audio in. |
required |
prefix
|
bool
|
Whether to add a data prefix to the base64 encoded string. |
False
|
Returns:
Type | Description |
---|---|
str
|
The base64 encoded audio data. |
Source code in src/mistral_common/audio.py
hertz_to_mel(freq)
Convert frequency from hertz to mels using the "slaney" mel-scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
freq
|
Union[float, ndarray]
|
The frequency, or multiple frequencies, in hertz (Hz). |
required |
Returns:
Type | Description |
---|---|
Union[float, ndarray]
|
The frequencies on the mel scale. |
Source code in src/mistral_common/audio.py
mel_filter_bank(num_frequency_bins, num_mel_bins, min_frequency, max_frequency, sampling_rate)
cached
Create a Mel filter bank matrix for converting frequency bins to the Mel scale.
This function generates a filter bank matrix that can be used to transform a spectrum represented in frequency bins to the Mel scale. The Mel scale is a perceptual scale of pitches judged by listeners to be equal in distance from one another.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_frequency_bins
|
int
|
The number of frequency bins in the input spectrum. |
required |
num_mel_bins
|
int
|
The number of desired Mel bins in the output. |
required |
min_frequency
|
float
|
The minimum frequency (in Hz) to consider. |
required |
max_frequency
|
float
|
The maximum frequency (in Hz) to consider. |
required |
sampling_rate
|
int
|
The sampling rate of the audio signal. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
A filter bank matrix of shape (num_mel_bins, num_frequency_bins) |
ndarray
|
that can be used to project frequency bin energies onto Mel bins. |
Source code in src/mistral_common/audio.py
mel_to_hertz(mels)
Convert frequency from mels to hertz using the "slaney" mel-scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mels
|
ndarray
|
The frequency, or multiple frequencies, in mels. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The frequencies in hertz. |