-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
better json support #2571
Comments
Whisper.cpp provides API for logging: whisper_log_set |
Also, you may set callback called on new segment: new_segment_callback require "whisper"
require "json"
# Set log callback to convert log to JSON format
Whisper.log_set ->(level, text, _) {
puts ({
level: level,
text: text
}).to_json
}, nil
whisper = Whisper::Context.new("../../models/ggml-base.bin")
params = Whisper::Params.new
# Helper function
def format_time(time_ms)
sec, decimal_part = time_ms.divmod(1000)
min, sec = sec.divmod(60)
hour, min = min.divmod(60)
"%02d:%02d:%02d.%03d" % [hour, min, sec, decimal_part]
end
# Set new segment callback to convert transcription result to JSON format
params.on_new_segment do |segment|
puts ({
start_time: format_time(segment.start_time),
end_time: format_time(segment.end_time),
text: segment.text
}).to_json
end
whisper.transcribe("../../samples/jfk.wav", params)
I used Ruby because I'm not familiar with C/C++, though essentially we should be able to do the same thing in C/C++. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can we get a way to output json to STDOUT?
The text was updated successfully, but these errors were encountered: