processing
audio
¶
convert_audio(src_file, dst_file, target_sr=None, normalize=False)
¶
Convert an audio file to a different sample rate and save it to a new file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_file |
str
|
Path to the source audio file. |
required |
dst_file |
str
|
Path to the destination audio file. |
required |
target_sr |
int
|
Target sample rate for the output audio file. |
None
|
normalize |
bool
|
If True, normalize the audio waveform before conversion. |
False
|
Returns:
Name | Type | Description |
---|---|---|
AudioSegment |
AudioSegment
|
The converted audio waveform as an AudioSegment object. |
Source code in aimet_ml/processing/audio.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
load_audio(file_path, target_sr=None, normalize=False)
¶
Load an audio file and return the waveform as a NumPy array and the target sample rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to the audio file. |
required |
target_sr |
int
|
Target sample rate for the audio waveform. |
None
|
normalize |
bool
|
If True, normalize the audio waveform. |
False
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, int]
|
Tuple[np.ndarray, int]: A tuple containing the waveform as a NumPy array and the target sample rate. |
Source code in aimet_ml/processing/audio.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
read_audio(file_path, target_sr=None, normalize=False)
¶
Read an audio file and return the waveform as an AudioSegment object with the target sample rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to the audio file. |
required |
target_sr |
int
|
Target sample rate for the audio waveform. |
None
|
normalize |
bool
|
If True, normalize the audio waveform. |
False
|
Returns:
Name | Type | Description |
---|---|---|
AudioSegment |
AudioSegment
|
Audio waveform as an AudioSegment object. |
Source code in aimet_ml/processing/audio.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
text
¶
clean_repeated_tokens(tokens)
¶
Remove sequences of repeated tokens from a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokens |
list[str]
|
List of tokens to clean. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
list[str]: List of tokens with repeated sequences removed. |
Source code in aimet_ml/processing/text.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
exclude_keywords(text, keywords)
¶
Check if any of the given keywords are present in the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to search for keywords. |
required |
keywords |
list[str]
|
List of keywords to check for. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
False if any keyword is present in the text, True otherwise. |
Source code in aimet_ml/processing/text.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
include_keywords(text, keywords)
¶
Check if any of the given keywords are present in the text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to search for keywords. |
required |
keywords |
list[str]
|
List of keywords to check for. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if any keyword is present in the text, False otherwise. |
Source code in aimet_ml/processing/text.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
trim_tokens(tokenizer, text, max_len)
¶
Trims a list of tokens generated by a tokenizer to ensure it doesn't exceed a maximum length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenizer |
PreTrainedTokenizer
|
The tokenizer used to tokenize the input text. |
required |
text |
str
|
The input text to tokenize and trim. |
required |
max_len |
int
|
The maximum allowed length for the list of tokens. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, int]
|
Tuple[str, int]: A tuple containing the trimmed text and the number of tokens in the trimmed list. |
Source code in aimet_ml/processing/text.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
video
¶
convert_video(src_file, dst_file, target_fps)
¶
Convert a video to a different frame rate and save to a new file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_file |
str
|
Path to the source video file. |
required |
dst_file |
str
|
Path to the output video file. |
required |
target_fps |
int
|
The target frames per second for the output video. |
required |
Source code in aimet_ml/processing/video.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
is_video(file_path)
¶
Check if a given file contains video streams.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the input file. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the file contains video streams, False otherwise. |
Source code in aimet_ml/processing/video.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
load_video(file_path)
¶
Load frames from a video file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the video file. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple
|
A tuple containing a list of frames and the frames per second (fps). |
Source code in aimet_ml/processing/video.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|