-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Test] 음성 녹음 테스트 코드 작성 #183
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Heim/Presentation/Presentation.xcodeproj/xcshareddata/xcschemes/Presentation.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1600" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "B307B3F22CD9B4B7001C5040" | ||
BuildableName = "Presentation.framework" | ||
BlueprintName = "Presentation" | ||
ReferencedContainer = "container:Presentation.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO" | ||
parallelizable = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "B307B3FC2CD9B4B7001C5040" | ||
BuildableName = "PresentationTests.xctest" | ||
BlueprintName = "PresentationTests" | ||
ReferencedContainer = "container:Presentation.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "B307B3F22CD9B4B7001C5040" | ||
BuildableName = "Presentation.framework" | ||
BlueprintName = "Presentation" | ||
ReferencedContainer = "container:Presentation.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,32 +10,44 @@ import Domain | |
import UIKit | ||
import Speech | ||
|
||
final class RecordManager { | ||
public protocol RecordManagerProtocol { | ||
var recognizedText: String { get } | ||
var minuteAndSeconds: Int { get } | ||
var voice: Voice? { get } | ||
var formattedTime: String { get } | ||
|
||
func setupSpeech() async throws | ||
func startRecording() throws | ||
func stopRecording() | ||
func resetAll() | ||
} | ||
|
||
public final class DefaultRecordManager: RecordManagerProtocol { | ||
// MARK: - 음성 인식을 위한 Properties | ||
Comment on lines
+24
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecordManager는 코드 품질을 개선할 여지가 많은 것 같습니다. |
||
private let speechRecognizer: SFSpeechRecognizer | ||
private let audioEngine: AVAudioEngine | ||
private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest? | ||
private var recognitionTask: SFSpeechRecognitionTask? | ||
|
||
// MARK: - 인식된 텍스트, 경과한 시간 | ||
private(set) var recognizedText: String | ||
private(set) var minuteAndSeconds: Int | ||
private(set) public var recognizedText: String | ||
private(set) public var minuteAndSeconds: Int | ||
|
||
// MARK: - 음성 녹음을 위한 Properties | ||
private var audioRecorder: AVAudioRecorder? | ||
private var recordingURL: URL | ||
private var timer: Timer? | ||
|
||
// MARK: - 음성 데이터 | ||
private(set) var voice: Voice? | ||
private(set) public var voice: Voice? | ||
|
||
var formattedTime: String { | ||
public var formattedTime: String { | ||
let minutes = minuteAndSeconds / 60 | ||
let seconds = minuteAndSeconds % 60 | ||
return String(format: "%02d:%02d", minutes, seconds) | ||
} | ||
|
||
init(locale: Locale = Locale(identifier: "ko-KR")) { | ||
public init(locale: Locale = Locale(identifier: "ko-KR")) { | ||
self.speechRecognizer = SFSpeechRecognizer(locale: locale)! | ||
self.audioEngine = AVAudioEngine() | ||
self.recognizedText = "" | ||
|
@@ -47,7 +59,7 @@ final class RecordManager { | |
} | ||
|
||
// MARK: - 녹음과정 준비 | ||
func setupSpeech() async throws { | ||
public func setupSpeech() async throws { | ||
let speechStatus = await withCheckedContinuation { continuation in | ||
SFSpeechRecognizer.requestAuthorization { status in | ||
continuation.resume(returning: status) | ||
|
@@ -68,7 +80,7 @@ final class RecordManager { | |
} | ||
} | ||
|
||
func startRecording() throws { | ||
public func startRecording() throws { | ||
if recognitionRequest == nil { | ||
// MARK: - 새로운 녹음 시작 | ||
try setupNewRecording() | ||
|
@@ -79,7 +91,7 @@ final class RecordManager { | |
} | ||
|
||
// MARK: - 일시중지 | ||
func stopRecording() { | ||
public func stopRecording() { | ||
audioEngine.pause() | ||
audioRecorder?.stop() | ||
|
||
|
@@ -93,7 +105,7 @@ final class RecordManager { | |
timer = nil | ||
} | ||
|
||
func resetAll() { | ||
public func resetAll() { | ||
audioEngine.stop() | ||
|
||
audioEngine.inputNode.removeTap(onBus: 0) | ||
|
@@ -116,7 +128,7 @@ final class RecordManager { | |
} | ||
} | ||
|
||
private extension RecordManager { | ||
private extension DefaultRecordManager { | ||
// MARK: - 녹음 재개 | ||
func resumeRecording() throws { | ||
do { | ||
|
@@ -139,19 +151,19 @@ private extension RecordManager { | |
// 오디오 세션 설정 | ||
let audioSession = AVAudioSession.sharedInstance() | ||
try audioSession.setCategory(.playAndRecord, | ||
mode: .default, | ||
options: [.defaultToSpeaker, .allowBluetooth]) | ||
mode: .default, | ||
options: [.defaultToSpeaker, .allowBluetooth]) | ||
try audioSession.setActive(true, options: .notifyOthersOnDeactivation) | ||
|
||
// PCM 설정 | ||
let settings: [String: Any] = [ | ||
AVFormatIDKey: Int(kAudioFormatLinearPCM), | ||
AVSampleRateKey: 44100.0, | ||
AVNumberOfChannelsKey: 2, // 스테레오로 변경 | ||
AVLinearPCMBitDepthKey: 16, | ||
AVLinearPCMIsFloatKey: false, | ||
AVLinearPCMIsBigEndianKey: false, | ||
AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue | ||
AVFormatIDKey: Int(kAudioFormatLinearPCM), | ||
AVSampleRateKey: 44100.0, | ||
AVNumberOfChannelsKey: 2, // 스테레오로 변경 | ||
AVLinearPCMBitDepthKey: 16, | ||
AVLinearPCMIsFloatKey: false, | ||
AVLinearPCMIsBigEndianKey: false, | ||
AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue | ||
] | ||
|
||
// 기존 파일이 있다면 제거 | ||
|
@@ -219,3 +231,4 @@ private extension RecordManager { | |
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.