audio_provider.h 2.5 KB

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