Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio session deactivation을 2초 지연 후 수행 #1072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final class ASRAgent: ASRAgentProtocol {
guard let asrRequest = asrRequest, let asrResult = asrResult else {
asrState = .idle
expectSpeech = nil
log.error("ASRRequest not exist")
log.error("ASR request: \(String(describing: asrRequest)), result: \(String(describing: asrResult))")
return
}
log.info("\(asrResult)")
Expand Down
11 changes: 10 additions & 1 deletion NuguClientKit/Sources/Client/NuguClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public class NuguClient {
// Private
private var pausedByInterruption = false
private let backgroundFocusHolder: BackgroundFocusHolder
private var audioDeactivateWorkItem: DispatchWorkItem?

init(
contextManager: ContextManageable,
Expand Down Expand Up @@ -541,6 +542,10 @@ extension NuguClient: FocusDelegate {
return delegate?.nuguClientShouldUpdateAudioSessionForFocusAquire() == true
}

if let audioDeactivateWorkItem = audioDeactivateWorkItem {
audioDeactivateWorkItem.cancel()
}

return audioSessionManager.updateAudioSession(requestingFocus: true) == true
}

Expand All @@ -550,8 +555,12 @@ extension NuguClient: FocusDelegate {
return
}

audioSessionManager.notifyAudioSessionDeactivation()
let audioDeactivateWorkItem = DispatchWorkItem {
audioSessionManager.notifyAudioSessionDeactivation()
}

DispatchQueue.global().asyncAfter(deadline: .now() + NuguClientConst.audioSessionDeactivationDelay, execute: audioDeactivateWorkItem)
self.audioDeactivateWorkItem = audioDeactivateWorkItem
}
}

Expand Down
24 changes: 24 additions & 0 deletions NuguClientKit/Sources/Client/NuguClientConst.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// NuguClientConst.swift
//
//
// Created by 김대철 on 2023/07/25.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum NuguClientConst {
static let audioSessionDeactivationDelay: TimeInterval = 2
}
4 changes: 4 additions & 0 deletions nugu-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@
73E8F35326C3C31500B99140 /* SpeechRecognizerAggregatorState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73E8F35226C3C31500B99140 /* SpeechRecognizerAggregatorState.swift */; };
73F0B71925CABC800025FC6A /* NuguClient+Builder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73F0B71825CABC800025FC6A /* NuguClient+Builder.swift */; };
73F0B72F25CAC4930025FC6A /* AudioSessionManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73F0B72E25CAC4930025FC6A /* AudioSessionManagerDelegate.swift */; };
73F0DF882A78A13000533B1B /* NuguClientConst.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73F0DF872A78A13000533B1B /* NuguClientConst.swift */; };
75021E4E259431B50014537C /* DisplayWebViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75021E4D259431B50014537C /* DisplayWebViewPresenter.swift */; };
75021E64259436930014537C /* DisplayWebViewPresenterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75021E63259436930014537C /* DisplayWebViewPresenterDelegate.swift */; };
75021EAC25945E670014537C /* AudioDisplayViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75021EAB25945E670014537C /* AudioDisplayViewPresenter.swift */; };
Expand Down Expand Up @@ -1192,6 +1193,7 @@
73E8F35226C3C31500B99140 /* SpeechRecognizerAggregatorState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeechRecognizerAggregatorState.swift; sourceTree = "<group>"; };
73F0B71825CABC800025FC6A /* NuguClient+Builder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NuguClient+Builder.swift"; sourceTree = "<group>"; };
73F0B72E25CAC4930025FC6A /* AudioSessionManagerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioSessionManagerDelegate.swift; sourceTree = "<group>"; };
73F0DF872A78A13000533B1B /* NuguClientConst.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NuguClientConst.swift; sourceTree = "<group>"; };
7500490F24766B1500B73DD8 /* AudioDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioDisplayView.swift; sourceTree = "<group>"; };
75021E4D259431B50014537C /* DisplayWebViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayWebViewPresenter.swift; sourceTree = "<group>"; };
75021E63259436930014537C /* DisplayWebViewPresenterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayWebViewPresenterDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1656,6 +1658,7 @@
1F2E803523966B1900569C59 /* Client */ = {
isa = PBXGroup;
children = (
73F0DF872A78A13000533B1B /* NuguClientConst.swift */,
1FFFF3D92375735E00C9A177 /* NuguClient.swift */,
7386DA9823CF279C002BF24C /* NuguClientDelegate.swift */,
73752BC625B8AFA6005C27DA /* NuguClientNotification.swift */,
Expand Down Expand Up @@ -4186,6 +4189,7 @@
7E341F3D25AFEEFD00734A45 /* SpeechRecognizerAggregator.swift in Sources */,
0600C3582570E4CF0071AEF3 /* ConfigurationStore.swift in Sources */,
066C9D2E25553EF0000C7800 /* MicInputProvider.swift in Sources */,
73F0DF882A78A13000533B1B /* NuguClientConst.swift in Sources */,
7330CD84237A77D800FCD6E9 /* KeywordDetector.swift in Sources */,
75E623D625E89EC800EAAE3C /* ASRBeepPlayerResourcesURL.swift in Sources */,
);
Expand Down