microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
snnn-patch-1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

include/ortx_extractor.h

91lines · modecode

1// C ABI header file for the onnxruntime-extensions tokenization module
2
3#pragma once
4
5#include "ortx_utils.h"
6
7typedef OrtxObject OrtxFeatureExtractor;
8typedef OrtxObject OrtxRawAudios;
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/**
15 * @brief Creates a feature extractor object.
16 *
17 * This function creates a feature extractor object based on the provided feature definition.
18 *
19 * @param[out] extractor Pointer to a pointer to the created feature extractor object.
20 * @param[in] fe_def The feature definition used to create the feature extractor.
21 *
22 * @return An error code indicating the result of the operation.
23 */
24extError_t ORTX_API_CALL OrtxCreateSpeechFeatureExtractor(OrtxFeatureExtractor** extractor, const char* fe_def);
25
26/**
27 * Loads a collection of audio files into memory.
28 *
29 * This function loads a collection of audio files specified by the `audio_paths` array
30 * into memory and returns a pointer to the loaded audio data in the `audios` parameter.
31 *
32 * @param audios A pointer to a pointer that will be updated with the loaded audio data.
33 * The caller is responsible for freeing the memory allocated for the audio data.
34 * @param audio_paths An array of strings representing the paths to the audio files to be loaded.
35 * @param num_audios The number of audio files to be loaded.
36 *
37 * @return An `extError_t` value indicating the success or failure of the operation.
38 */
39extError_t ORTX_API_CALL OrtxLoadAudios(OrtxRawAudios** audios, const char* const* audio_paths, size_t num_audios);
40
41/**
42 * @brief Creates an array of raw audio objects, which refers to the audio data and sizes provided.
43 *
44 * This function creates an array of raw audio objects based on the provided data and sizes. The data will be stored in
45 * the `audios` parameter.
46 *
47 * @param audios Pointer to the variable that will hold the created raw audio objects.
48 * @param data Array of pointers to the audio data.
49 * @param sizes Array of pointers to the sizes of the audio data.
50 * @param num_audios Number of audio objects to create.
51 *
52 * @return extError_t Error code indicating the success or failure of the operation.
53 */
54extError_t ORTX_API_CALL OrtxCreateRawAudios(OrtxRawAudios** audios, const void* data[], const int64_t sizes[], size_t num_audios);
55
56/**
57 * @brief Calculates the log mel spectrogram for a given audio using the specified feature extractor.
58 *
59 * This function takes an instance of the OrtxFeatureExtractor struct, an instance of the OrtxRawAudios struct,
60 * and a pointer to an OrtxTensorResult pointer. It calculates the log mel spectrogram for the given audio using
61 * the specified feature extractor and stores the result in the provided log_mel pointer.
62 *
63 * @param extractor The feature extractor to use for calculating the log mel spectrogram.
64 * @param audio The raw audio data to process.
65 * @param log_mel A pointer to an OrtxTensorResult pointer where the result will be stored.
66 * @return An extError_t value indicating the success or failure of the operation.
67 */
68extError_t ORTX_API_CALL OrtxSpeechLogMel(OrtxFeatureExtractor* extractor, OrtxRawAudios* audio, OrtxTensorResult** log_mel);
69
70
71/**
72 * @brief Extracts log-mel features from raw audio data using a feature extractor.
73 *
74 * This function processes the input audio buffers through the provided feature extractor,
75 * producing log-mel spectrogram outputs suitable for inference or further signal analysis.
76 *
77 * @param extractor A pointer to an OrtxFeatureExtractor object that defines the feature
78 * extraction pipeline and processing parameters.
79 * @param audio A pointer to an OrtxRawAudios structure containing raw audio data buffers
80 * and associated metadata (e.g., sampling rate, channels).
81 * @param result A pointer to an OrtxTensorResult pointer that will be allocated and set to
82 * hold the resulting log-mel spectrogram data and other outputs based on json configuration.
83 *
84 * @return An extError_t value indicating success or error status. Returns
85 * EXT_SUCCESS on success, or an appropriate error code if extraction fails.
86 */
87extError_t ORTX_API_CALL OrtxFeatureExtraction(OrtxFeatureExtractor* extractor, OrtxRawAudios* audio, OrtxTensorResult** result);
88
89#ifdef __cplusplus
90}
91#endif
92