WhisperKit icon indicating copy to clipboard operation
WhisperKit copied to clipboard

how to fix "Ambiguous use of 'transcribe(audioPath:decodeOptions:callback:)'"

Open zacfire opened this issue 9 months ago • 0 comments

i try many way, but still show:Ambiguous use of 'transcribe(audioPath:decodeOptions:callback:)

Here is code:

 func stopRecording() {
        audioRecorder?.stop()
        if let url = audioRecorder?.url {
            transcribeAudio(audioPath: url.path)
        }
    }

func transcribeAudio(audioPath: String) {
        Task {
            do {
                let whisper = try await WhisperKit()
                let results = try await whisper.transcribe(audioPath: audioPath)
                DispatchQueue.main.async {
                    if let result = results.first, !result.text.isEmpty {
                        self.transcription = result.text
                        let newRecording = Recording(
                            name: "Recording \(self.recordings.count + 1)",
                            createdAt: Date(),
                            fileURL: URL(fileURLWithPath: audioPath),
                            transcript: result.text
                        )
                        self.recordings.append(newRecording)
                    }
                }
            } catch {
                DispatchQueue.main.async {
                    print("Transcription failed: \(error)")
                }
            }
        }
    } 

zacfire avatar May 22 '24 03:05 zacfire