Recording access trouble - cho407/WhisperCaptionPro GitHub Wiki
๋ง์ดํฌ ์ฌ์ฉ ๊ถํ ๊ด๋ จ ํธ๋ฌ๋ธ ์ํ
๋ฌธ์
์ฐ์ ์ฑ์์ ๋ง์ดํฌ, ์นด๋ฉ๋ผ, ๋ธ๋ฃจํฌ์ค ๋ฑ๋ฑ ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ์ฌ์ฉ ๊ถํ์ ๋์๋ฅผ ํด์ผํ๋ค. ๊ทธ๋ ๊ฒ ๋๋ฌธ์ Info.plist ์๋ค๊ฐ Privacy - Microphone Usage Description์ ์ถ๊ฐํด ์ด๋ค ์ฉ๋์์ ์ฌ์ฉ๊ถํ์ ์์ฒญํ๋์ง ํ์ ์๋์ด ๋จ๊ณ ๊ทธ๊ฒ์ ์ฌ์ฉ์๊ฐ ๋์ํ ์ง ๋์ํ์ง ์์์ง๋ฅผ ๊ฒฐ์ ํ๋ ๊ตฌ์กฐ์ธ๋ฐ ํ์ ์๋์ด ๋จ์ง ์์์ ๊ทธ ์์ธ์ ์ฐพ๊ธฐ์ํด ๋ง์ด ํค๋งธ๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
์ฐ์ ์ฝ๋์ ๋ก์ง์ ์ดํด๋ณด์๋ค.
/// ๋
น์ ์์
func startRecording(_ loop: Bool) {
if let audioProcessor = whisperKit?.audioProcessor {
Task(priority: .userInitiated) {
guard await AudioProcessor.requestRecordPermission() else {
print("Microphone access was not granted.")
return
}
var deviceId: DeviceID?
#if os(macOS)
if settings.selectedAudioInput != "No Audio Input",
let devices = audioState.audioDevices,
let device = devices
.first(where: { $0.name == settings.selectedAudioInput }) {
deviceId = device.id
}
if deviceId == nil {
throw WhisperError.microphoneUnavailable()
}
#endif
try? audioProcessor.startRecordingLive(inputDeviceID: deviceId) { _ in
DispatchQueue.main.async {
// ์ ์ฌ ์ํ ์
๋ฐ์ดํธ
self.transcriptionState.bufferEnergy = self.whisperKit?.audioProcessor
.relativeEnergy ?? []
self.transcriptionState
.bufferSeconds = Double(self.whisperKit?.audioProcessor.audioSamples
.count ?? 0) / Double(WhisperKit.sampleRate)
}
}
audioState.isRecording = true
audioState.isTranscribing = true
if loop { realtimeLoop() }
}
}
}
์์๊ฐ์ ๋ก์ง์ธ๋ฐ WhisperKit์ AudioProcessor๋ฅผ ํตํด์ requestRecordPermission()๊ถํ์ ํ์ธํ๊ณ ๋ น์์ ์์ํ๋ ๊ตฌ์กฐ์ธ๋ฐ ์ฌ์ค ๊ตฌ์กฐ์ ๋ฌธ์ ๋ ์์์ง๋ง ๋จ๊ณ๋ณ ๋๋ฒ๊น ์ ์ํํ๊ธฐ ์ํด ContentView์ .onAppear ๋ฉ์๋์ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ฅผ ๋ฃ์ ํ ์คํํด ๋ณด์๋ค.
if #available(macOS 14, *) {
Task {
let granted = await AVAudioApplication.requestRecordPermission()
print("๋ง์ดํฌ ๊ถํ \(granted ? "ํ์ฉ๋จ" : "๊ฑฐ๋ถ๋จ")")
}
} else {
let microphoneStatus = AVCaptureDevice.authorizationStatus(for: .audio)
switch microphoneStatus {
case .notDetermined:
AVCaptureDevice.requestAccess(for: .audio) { granted in
DispatchQueue.main.async {
print("๋ง์ดํฌ ๊ถํ \(granted ? "ํ์ฉ๋จ" : "๊ฑฐ๋ถ๋จ")")
}
}
case .authorized:
print("๋ง์ดํฌ ๊ถํ ์ด๋ฏธ ํ์ฉ๋จ")
default:
print("๋ง์ดํฌ ๊ถํ์ด ๊ฑฐ๋ถ๋์๊ฑฐ๋ ์ ํ๋จ")
}
}
ํ์ง๋ง ์ฌ์ ํ ํ์ ์ฐฝ์ ๋จ์ง ์๊ณ ๊ถํ์ด ๊ฑฐ๋ถ๋๋ค๋ ๋ฉ์ธ์ง๋ง print๋์ด์ ํ์ฐธ์ ๊ณ ์ํ๋์ค ์ด์ ๋ฅผ ๋ฐ๊ฒฌํ์๋ค.
Targets -> Signing&Capabilities ์ Audio Input ์ค์ ์ ์ฒดํฌํ์ง ์์ ์ฌ์ค์ ๋ฐ๊ฒฌ...
๊ทธ๋์ ๋ค์๊ณผ ๊ฐ์ด ์ฒดํฌํ ํ ์คํํ๋ ์ ์์ ์ผ๋ก ์๋ ๋์๋ค.