AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AudioInjectorMicrophone.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_DIAGNOSTICS_INCLUDE_DIAGNOSTICS_AUDIOINJECTORMICROPHONE_H_
17 #define ALEXA_CLIENT_SDK_DIAGNOSTICS_INCLUDE_DIAGNOSTICS_AUDIOINJECTORMICROPHONE_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <thread>
22 
27 
29 
30 namespace alexaClientSDK {
31 namespace diagnostics {
32 
35 public:
43  static std::unique_ptr<AudioInjectorMicrophone> create(
44  const std::shared_ptr<avsCommon::avs::AudioInputStream>& stream,
45  const alexaClientSDK::avsCommon::utils::AudioFormat& compatibleAudioFormat);
46 
49  bool stopStreamingMicrophoneData() override;
50  bool startStreamingMicrophoneData() override;
51  bool isStreaming() override;
53 
60  void injectAudio(const std::vector<uint16_t>& audioData);
61 
66 
67 private:
75  const std::shared_ptr<avsCommon::avs::AudioInputStream>& stream,
76  const alexaClientSDK::avsCommon::utils::AudioFormat& compatibleAudioFormat);
77 
78  /*
79  * Reset m_injectionData to empty and m_injectionDataCounter to 0.
80  */
81  void resetAudioInjection();
82 
86  bool initialize();
87 
91  void startTimer();
92 
96  void write();
97 
99  const std::shared_ptr<avsCommon::avs::AudioInputStream> m_audioInputStream;
100 
102  std::mutex m_mutex;
103 
105  std::shared_ptr<avsCommon::avs::AudioInputStream::Writer> m_writer;
106 
108  bool m_isStreaming;
109 
112 
114  unsigned int m_maxSampleCountPerTimeout;
115 
117  alexaClientSDK::avsCommon::avs::AudioInputStream::Buffer m_silenceBuffer;
118 
120  std::vector<uint16_t> m_injectionData;
121 
123  unsigned long m_injectionDataCounter;
124 };
125 
126 } // namespace diagnostics
127 } // namespace alexaClientSDK
128 
129 #endif // ALEXA_CLIENT_SDK_DIAGNOSTICS_INCLUDE_DIAGNOSTICS_AUDIOINJECTORMICROPHONE_H_
void injectAudio(const std::vector< uint16_t > &audioData)
This represents a microphone which injects audio data into the shared data stream.
Definition: AudioInjectorMicrophone.h:34
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
static std::unique_ptr< AudioInjectorMicrophone > create(const std::shared_ptr< avsCommon::avs::AudioInputStream > &stream, const alexaClientSDK::avsCommon::utils::AudioFormat &compatibleAudioFormat)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
This acts as an interface to record audio input from a microphone.
Definition: MicrophoneInterface.h:28

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0