Skip to content

Commit

Permalink
Update whisper.cpp to latest version, use new progress callback
Browse files Browse the repository at this point in the history
  • Loading branch information
exPHAT committed May 16, 2023
1 parent 92af8ea commit 9ce1648
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions Sources/SwiftWhisper/Whisper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Whisper {
self.unmanagedSelf = unmanagedSelf
params.new_segment_callback_user_data = unmanagedSelf.toOpaque()
params.encoder_begin_callback_user_data = unmanagedSelf.toOpaque()
params.progress_callback_user_data = unmanagedSelf.toOpaque()

// swiftlint:disable line_length
params.new_segment_callback = { (ctx: OpaquePointer?, _: OpaquePointer?, newSegmentCount: Int32, userData: UnsafeMutableRawPointer?) in
Expand All @@ -66,17 +67,6 @@ public class Whisper {
))
}

if let frameCount = whisper.frameCount,
let lastSegmentTime = newSegments.last?.endTime {

let fileLength = Double(frameCount * 1000) / Double(WHISPER_SAMPLE_RATE)
let progress = Double(lastSegmentTime) / Double(fileLength)

DispatchQueue.main.async {
delegate.whisper(whisper, didUpdateProgress: progress)
}
}

DispatchQueue.main.async {
delegate.whisper(whisper, didProcessNewSegments: newSegments, atIndex: Int(startIndex))
}
Expand All @@ -92,6 +82,15 @@ public class Whisper {

return true
}

params.progress_callback = { (_: OpaquePointer?, _: OpaquePointer?, progress: Int32, userData: UnsafeMutableRawPointer?) in

Check warning on line 86 in Sources/SwiftWhisper/Whisper.swift

View workflow job for this annotation

GitHub Actions / lint

Line Length Violation: Line should be 120 characters or less; currently it has 131 characters (line_length)
guard let userData else { return }
let whisper = Unmanaged<Whisper>.fromOpaque(userData).takeUnretainedValue()

DispatchQueue.main.async {
whisper.delegate?.whisper(whisper, didUpdateProgress: Double(progress) / 100)
}
}
}

private func cleanupCallbacks() {
Expand Down
2 changes: 1 addition & 1 deletion whisper.cpp
Submodule whisper.cpp updated 88 files
+98 βˆ’0 .github/workflows/build.yml
+7 βˆ’1 .gitignore
+149 βˆ’29 CMakeLists.txt
+1 βˆ’1 LICENSE
+99 βˆ’38 Makefile
+133 βˆ’6 README.md
+4 βˆ’0 bindings/go/params.go
+12 βˆ’3 bindings/go/pkg/whisper/context.go
+5 βˆ’3 bindings/go/pkg/whisper/interface.go
+9 βˆ’1 bindings/go/whisper.go
+1 βˆ’1 bindings/ios
+1 βˆ’1 bindings/javascript/package.json
+1 βˆ’1 bindings/javascript/whisper.js
+146 βˆ’0 coreml/whisper-decoder-impl.h
+201 βˆ’0 coreml/whisper-decoder-impl.m
+142 βˆ’0 coreml/whisper-encoder-impl.h
+197 βˆ’0 coreml/whisper-encoder-impl.m
+22 βˆ’0 coreml/whisper-encoder.h
+63 βˆ’0 coreml/whisper-encoder.mm
+7 βˆ’2 examples/CMakeLists.txt
+16 βˆ’8 examples/addon.node/__test__/whisper.spec.js
+1 βˆ’18 examples/addon.node/addon.cpp
+3 βˆ’3 examples/bench.wasm/CMakeLists.txt
+65 βˆ’9 examples/bench.wasm/index-tmpl.html
+0 βˆ’25 examples/command.wasm/emscripten.cpp
+27 βˆ’0 examples/command.wasm/index-tmpl.html
+1 βˆ’1 examples/command/CMakeLists.txt
+0 βˆ’25 examples/command/command.cpp
+235 βˆ’0 examples/common-ggml.cpp
+18 βˆ’0 examples/common-ggml.h
+377 βˆ’0 examples/common.cpp
+88 βˆ’3 examples/common.h
+10 βˆ’3 examples/helpers.js
+94 βˆ’27 examples/main/main.cpp
+6 βˆ’0 examples/quantize/CMakeLists.txt
+3 βˆ’0 examples/quantize/README.md
+221 βˆ’0 examples/quantize/quantize.cpp
+27 βˆ’0 examples/stream.wasm/index-tmpl.html
+1 βˆ’1 examples/stream/CMakeLists.txt
+23 βˆ’18 examples/stream/stream.cpp
+0 βˆ’1 examples/talk-llama/.gitignore
+1 βˆ’1 examples/talk-llama/CMakeLists.txt
+14 βˆ’0 examples/talk-llama/README.md
+23 βˆ’0 examples/talk-llama/eleven-labs.py
+433 βˆ’0 examples/talk-llama/llama-util.h
+2,021 βˆ’959 examples/talk-llama/llama.cpp
+134 βˆ’26 examples/talk-llama/llama.h
+23 βˆ’0 examples/talk-llama/prompts/talk-alpaca.txt
+1 βˆ’0 examples/talk-llama/speak.sh
+159 βˆ’15 examples/talk-llama/talk-llama.cpp
+1 βˆ’0 examples/talk.wasm/CMakeLists.txt
+111 βˆ’226 examples/talk.wasm/gpt-2.cpp
+2 βˆ’8 examples/talk.wasm/gpt-2.h
+27 βˆ’0 examples/talk.wasm/index-tmpl.html
+1 βˆ’1 examples/talk/.gitignore
+3 βˆ’11 examples/talk/CMakeLists.txt
+23 βˆ’0 examples/talk/eleven-labs.py
+106 βˆ’219 examples/talk/gpt-2.cpp
+2 βˆ’8 examples/talk/gpt-2.h
+1 βˆ’0 examples/talk/speak.sh
+2 βˆ’0 examples/whisper.android/README.md
+10 βˆ’1 examples/whisper.objc/README.md
+32 βˆ’1 examples/whisper.objc/whisper.objc.xcodeproj/project.pbxproj
+6 βˆ’3 examples/whisper.swiftui/README.md
+3 βˆ’3 examples/whisper.wasm/CMakeLists.txt
+2 βˆ’2 examples/whisper.wasm/README.md
+8 βˆ’2 examples/whisper.wasm/emscripten.cpp
+111 βˆ’20 examples/whisper.wasm/index-tmpl.html
+37 βˆ’15 extra/bench-all.sh
+45 βˆ’0 extra/quantize-all.sh
+18 βˆ’0 extra/sync-ggml.sh
+898 βˆ’0 ggml-cuda.cu
+21 βˆ’0 ggml-cuda.h
+361 βˆ’0 ggml-opencl.c
+24 βˆ’0 ggml-opencl.h
+7,754 βˆ’2,808 ggml.c
+922 βˆ’567 ggml.h
+17 βˆ’5 models/README.md
+17 βˆ’21 models/convert-h5-to-ggml.py
+26 βˆ’31 models/convert-pt-to-ggml.py
+331 βˆ’0 models/convert-whisper-to-coreml.py
+82 βˆ’0 models/download-coreml-model.sh
+2 βˆ’2 models/download-ggml-model.sh
+29 βˆ’0 models/generate-coreml-interface.sh
+25 βˆ’0 models/generate-coreml-model.sh
+8 βˆ’3 tests/run-tests.sh
+860 βˆ’606 whisper.cpp
+12 βˆ’3 whisper.h

0 comments on commit 9ce1648

Please sign in to comment.