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_FEATURE_PROVIDER_H_ 17 #define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_ 18 19 #include "tensorflow/lite/c/common.h" 20 #include "tensorflow/lite/micro/micro_error_reporter.h" 21 22 // Binds itself to an area of memory intended to hold the input features for an 23 // audio-recognition neural network model, and fills that data area with the 24 // features representing the current audio input, for example from a microphone. 25 // The audio features themselves are a two-dimensional array, made up of 26 // horizontal slices representing the frequencies at one point in time, stacked 27 // on top of each other to form a spectrogram showing how those frequencies 28 // changed over time. 29 class FeatureProvider { 30 public: 31 // Create the provider, and bind it to an area of memory. This memory should 32 // remain accessible for the lifetime of the provider object, since subsequent 33 // calls will fill it with feature data. The provider does no memory 34 // management of this data. 35 FeatureProvider(int feature_size, int8_t* feature_data); 36 ~FeatureProvider(); 37 38 // Fills the feature data with information from audio inputs, and returns how 39 // many feature slices were updated. 40 TfLiteStatus PopulateFeatureData(tflite::ErrorReporter* error_reporter, 41 int32_t last_time_in_ms, int32_t time_in_ms, 42 int* how_many_new_slices); 43 44 private: 45 int feature_size_; 46 int8_t* feature_data_; 47 // Make sure we don't try to use cached information if this is the first call 48 // into the provider. 49 bool is_first_run_; 50 }; 51 52 #endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_ 53