1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ 17 #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ 18 19 #include "tensorflow/lite/c/common.h" 20 #include "tensorflow/lite/micro/micro_error_reporter.h" 21 22 // This is an abstraction around an audio source like a microphone, and is 23 // expected to return 16-bit PCM sample data for a given point in time. The 24 // sample data itself should be used as quickly as possible by the caller, since 25 // to allow memory optimizations there are no guarantees that the samples won't 26 // be overwritten by new data in the future. In practice, implementations should 27 // ensure that there's a reasonable time allowed for clients to access the data 28 // before any reuse. 29 // The reference implementation can have no platform-specific dependencies, so 30 // it just returns an array filled with zeros. For real applications, you should 31 // ensure there's a specialized implementation that accesses hardware APIs. 32 TfLiteStatus GetAudioSamples(tflite::ErrorReporter* error_reporter, 33 int start_ms, int duration_ms, 34 int* audio_samples_size, int16_t** audio_samples); 35 36 // Returns the time that audio data was last captured in milliseconds. There's 37 // no contract about what time zero represents, the accuracy, or the granularity 38 // of the result. Subsequent calls will generally not return a lower value, but 39 // even that's not guaranteed if there's an overflow wraparound. 40 // The reference implementation of this function just returns a constantly 41 // incrementing value for each call, since it would need a non-portable platform 42 // call to access time information. For real applications, you'll need to write 43 // your own platform-specific implementation. 44 int32_t LatestAudioTimestamp(); 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 extern int audio_install_codec_driver(); 50 #ifdef __cplusplus 51 } // extern C 52 #endif 53 #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ 54