-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpv_octopus.h
162 lines (140 loc) · 5.48 KB
/
pv_octopus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright 2020-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
file accompanying this source.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
*/
#ifndef PV_OCTOPUS_H
#define PV_OCTOPUS_H
#include <stdint.h>
#include "picovoice.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Forward declaration for Octopus Speech-to-Index engine.
*/
typedef struct pv_octopus pv_octopus_t;
/**
* Constructor.
*
* @param access_key AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)
* @param model_path Absolute path to the file containing model parameters.
* @param[out] object Constructed instance of Octopus.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT', 'PV_STATUS_IO_ERROR', 'PV_STATUS_OUT_OF_MEMORY',
* 'PV_STATUS_RUNTIME_ERROR', 'PV_STATUS_ACTIVATION_ERROR', 'PV_STATUS_ACTIVATION_LIMIT_REACHED',
* 'PV_STATUS_ACTIVATION_THROTTLED', or 'PV_STATUS_ACTIVATION_REFUSED' on failure
*/
PV_API pv_status_t pv_octopus_init(
const char *access_key,
const char *model_path,
pv_octopus_t **object);
/**
* Destructor.
*
* @param object Octopus object.
*/
PV_API void pv_octopus_delete(pv_octopus_t *object);
/**
* Determines size required for indices buffer when indexing audio data.
*
* @param object Octopus object.
* @param num_samples Number of audio samples to index.
* @param num_indices_bytes Size of index metadata in bytes.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT' on failure
*/
PV_API pv_status_t pv_octopus_index_size(
pv_octopus_t *object,
int32_t num_samples,
int32_t *num_indices_bytes);
/**
* Indexes audio data.
*
* @param object Octopus object.
* @param pcm Audio data. The audio needs to have a sample rate equal to 'pv_sample_rate()' and be 16-bit
* linearly-encoded. Octopus operates on single-channel audio.
* @param num_samples Number of audio samples to index.
* @param indices Buffer to store index metadata. Must be pre-allocated with result of `pv_octopus_index_size()`.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT', 'PV_STATUS_OUT_OF_MEMORY', 'PV_STATUS_RUNTIME_ERROR',
* 'PV_STATUS_ACTIVATION_ERROR', 'PV_STATUS_ACTIVATION_LIMIT_REACHED', 'PV_STATUS_ACTIVATION_THROTTLED', or
* 'PV_STATUS_ACTIVATION_REFUSED' on failure
*/
PV_API pv_status_t pv_octopus_index(
pv_octopus_t *object,
const int16_t *pcm,
int32_t num_samples,
void *indices);
/**
* Determines size required for indices buffer when indexing an audio file.
*
* @param object Octopus object.
* @param path Absolute path to the audio file. The file needs to have a sample rate equal to or greater than
* `pv_sample_rate()`. The supported formats are: `3gp (AMR)`, `FLAC`, `MP3`, `MP4/m4a (AAC)`, `Ogg`, `WAV`, `WebM`.
* Files with stereo audio are mixed into a single mono channel and then processed.
* @param num_indices_bytes Size of index metadata in bytes.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT' on failure
*/
PV_API pv_status_t pv_octopus_index_file_size(
pv_octopus_t *object,
const char *path,
int32_t *num_indices_bytes);
/**
* Indexes an audio file.
*
* @param object Octopus object.
* @param path Absolute path to the audio file. The file needs to have a sample rate equal to or greater than
* `pv_sample_rate()`. The supported formats are: `3gp (AMR)`, `FLAC`, `MP3`, `MP4/m4a (AAC)`, `Ogg`, `WAV`, `WebM`.
* Files with stereo audio are mixed into a single mono channel and then processed.
* @param indices Buffer to store index metadata. Must be pre-allocated with result of `pv_octopus_index_file_size()`.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT' or 'PV_STATUS_OUT_OF_MEMORY',
* 'PV_STATUS_RUNTIME_ERROR', 'PV_STATUS_ACTIVATION_ERROR', 'PV_STATUS_ACTIVATION_LIMIT_REACHED',
* 'PV_STATUS_ACTIVATION_THROTTLED', or 'PV_STATUS_ACTIVATION_REFUSED' on failure
*/
PV_API pv_status_t pv_octopus_index_file(
pv_octopus_t *object,
const char *path,
void *indices);
/**
* Container representing a matched utterance.
*/
typedef struct {
float start_sec;
float end_sec;
float probability;
} pv_octopus_match_t;
/**
* Searches index metadata for occurrences of a given phrase.
*
* @param object Octopus object.
* @param indices Index metadata.
* @param num_indices_bytes Size of index metadata in bytes.
* @param phrase Search phrase.
* @param matches Utterances matching the search phrase.
* @param num_matches Numbers of matched utterances.
* @return Status code. Returns 'PV_STATUS_INVALID_ARGUMENT' or 'PV_STATUS_OUT_OF_MEMORY' on failure.
*/
PV_API pv_status_t pv_octopus_search(
pv_octopus_t *object,
const void *indices,
int32_t num_indices_bytes,
const char *phrase,
pv_octopus_match_t **matches,
int32_t *num_matches);
/**
* Deletes matches returned from `pv_octopus_search()`
*
* @param matches matched utterances returned from `pv_octopus_search()`
*/
PV_API void pv_octopus_matches_delete(pv_octopus_match_t *matches);
/**
* Getter for version.
*
* @return Version.
*/
PV_API const char *pv_octopus_version(void);
#ifdef __cplusplus
}
#endif
#endif // PV_OCTOPUS_H