AWS Lambda Event Handler
audio_classifier.lambda_function
lambda_handler(event, context)
Event listener for S3 event and calls the daily logger function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
AWS Event
|
A JSON-formatted document that contains data for a Lambda function to process. |
required |
context |
_type_
|
An object that provides methods and properties that provide information about the invocation, function, and runtime environment. |
required |
Raises:
Type | Description |
---|---|
Exception
|
Failed to retrieve audio. |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
String-formatted JSON object containing statusCode and prediction. |
Source code in src/audio_classifier/lambda_function.py
predict(audio_array, onnx_model_path)
Makes a prediction with ONNX model given audio array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_array |
np.ndarray
|
Array of audio to be predicted. |
required |
onnx_model_path |
str
|
Path to ONNX model predictor. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Prediction, either "ADULT or "CHILD". |
Source code in src/audio_classifier/lambda_function.py
preprocess(audio_array)
Truncates/pads and normalizes audio array for classification using Wav2Vec2 model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_array |
np.ndarray
|
Array of input audio. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
np.ndarray: Pre-processed audio array ready for classifier. |
Source code in src/audio_classifier/lambda_function.py
read_audio_as_array(audio)
Read audio from S3 url audio
, resample to 16KHz, and return as Numpy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio |
str
|
S3 audio URL. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
np.ndarray: Array of audio retrieved from S3. |