Skip to content

Commit

Permalink
fix #557
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Sep 23, 2023
1 parent e5a5e03 commit da46488
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Sources/KSPlayer/MEPlayer/AudioRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
//

import Foundation
#if canImport(Speech)

#if enableAudioRecognizer && canImport(Speech)
import Speech
#endif

public class AudioRecognizer {
#if canImport(Speech)
#if enableAudioRecognizer && canImport(Speech)
private let recognitionRequest: SFSpeechAudioBufferRecognitionRequest
private let speechRecognizer: SFSpeechRecognizer
#endif
public init(locale: Locale, handler: @escaping (String) -> Void) {
#if canImport(Speech)
#if enableAudioRecognizer && canImport(Speech)
recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
recognitionRequest.shouldReportPartialResults = true
recognitionRequest.requiresOnDeviceRecognition = true
speechRecognizer = SFSpeechRecognizer(locale: locale)!
let recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest) { result, _ in
_ = speechRecognizer.recognitionTask(with: recognitionRequest) { result, _ in
if let result {
let text = result.bestTranscription.formattedString
handler(text)
Expand All @@ -31,7 +32,7 @@ public class AudioRecognizer {
}

func append(frame: AudioFrame) {
#if canImport(Speech)
#if enableAudioRecognizer && canImport(Speech)
if let sampleBuffer = frame.toCMSampleBuffer() {
recognitionRequest.appendAudioSampleBuffer(sampleBuffer)
}
Expand Down

0 comments on commit da46488

Please sign in to comment.