2 * Copyright 2018-2019 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #ifndef _WAKEUP_AUDIO_MANAGER_H_
19 #define _WAKEUP_AUDIO_MANAGER_H_
27 #include <multi_assistant_service.h>
29 #include <sound_manager.h>
30 #include <sound_manager_internal.h>
32 namespace multiassistant
39 class IAudioEventObserver
42 virtual ~IAudioEventObserver() = default;
43 virtual bool on_recording_audio_data(long time, void* data, int len) = 0;
44 virtual bool on_streaming_audio_data(
45 mas_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
50 RECORDING_SESSION_WAKE_WORD,
51 RECORDING_SESSION_UTTERANCE,
52 RECORDING_SESSION_FOLLOW_UP,
59 CAudioManager(IAudioEventObserver *observer);
62 CAudioManager(const CAudioManager&) = delete;
63 CAudioManager& operator=(const CAudioManager&) = delete;
68 void sound_focus_changed();
70 void subscribe(IAudioEventObserver *observer);
71 void unsubscribe(IAudioEventObserver *observer);
73 void start_recording(bool proactive);
74 void stop_recording(bool proactive);
76 void set_recording_session(recording_session session);
78 void feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len);
79 void finalize_audio_data();
80 void clear_audio_data();
82 void start_streaming_current_utterance_data(long start_time = 0);
83 void stop_streaming_current_utterance_data();
85 void start_streaming_previous_utterance_data();
86 void stop_streaming_previous_utterance_data();
88 void start_streaming_follow_up_data();
89 void stop_streaming_follow_up_data();
91 void set_background_volume(double ratio);
93 void add_audio_data(mas_speech_data& data, long time);
94 void notify_audio_data_recording(long time, void* data, int len);
96 void streaming_previous_audio_data_thread_func();
97 void streaming_audio_data_thread_func(long start_time);
99 int mSoundFocusWatchId{0};
100 bool mRecordingRequired{false};
101 bool mIsRecording{false};
103 vector<IAudioEventObserver*> mObservers;
105 thread mStreamingThread;
106 atomic_bool mStopStreamingThread{false};
108 thread mStreamingPreviousThread;
109 atomic_bool mStopStreamingPreviousThread{false};
111 static constexpr long mAudioRecordingDurationMilliseconds = 10 * 1000;
114 mas_speech_data data;
115 } mas_speech_data_with_time;
116 vector<mas_speech_data_with_time> mPreviousAudioData;
117 list<mas_speech_data_with_time> mAudioData;
120 bool mVoiceKeyPressed{false};
126 #endif /* _WAKEUP_AUDIO_MANAGER_H_ */