-
Notifications
You must be signed in to change notification settings - Fork 343
Testing #333
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
Testing #333
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -274,35 +274,41 @@ STTResult WhisperCppSTT::transcribe_internal(const std::vector<float>& audio, | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const int n_segments = whisper_full_n_segments(ctx_); | ||||||||||||||||||||||||||||||||||
| std::string full_text; | ||||||||||||||||||||||||||||||||||
| full_text.reserve(n_segments * 64); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| result.segments.reserve(n_segments); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (word_timestamps) { | ||||||||||||||||||||||||||||||||||
| result.word_timings.reserve(n_segments * 15); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for (int i = 0; i < n_segments; ++i) { | ||||||||||||||||||||||||||||||||||
| const char* text = whisper_full_get_segment_text(ctx_, i); | ||||||||||||||||||||||||||||||||||
| if (text) { | ||||||||||||||||||||||||||||||||||
| full_text += text; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AudioSegment segment; | ||||||||||||||||||||||||||||||||||
| result.segments.emplace_back(); | ||||||||||||||||||||||||||||||||||
| AudioSegment& segment = result.segments.back(); | ||||||||||||||||||||||||||||||||||
| segment.text = text; | ||||||||||||||||||||||||||||||||||
| segment.start_time_ms = whisper_full_get_segment_t0(ctx_, i) * 10.0; | ||||||||||||||||||||||||||||||||||
| segment.end_time_ms = whisper_full_get_segment_t1(ctx_, i) * 10.0; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| float no_speech_prob = whisper_full_get_segment_no_speech_prob(ctx_, i); | ||||||||||||||||||||||||||||||||||
| segment.confidence = 1.0f - no_speech_prob; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| result.segments.push_back(segment); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (word_timestamps) { | ||||||||||||||||||||||||||||||||||
| const int n_tokens = whisper_full_n_tokens(ctx_, i); | ||||||||||||||||||||||||||||||||||
| for (int j = 0; j < n_tokens; ++j) { | ||||||||||||||||||||||||||||||||||
| whisper_token_data token_data = whisper_full_get_token_data(ctx_, i, j); | ||||||||||||||||||||||||||||||||||
| const char* token_text = whisper_full_get_token_text(ctx_, i, j); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (token_text && token_text[0] != '\0' && token_text[0] != '<') { | ||||||||||||||||||||||||||||||||||
| WordTiming word; | ||||||||||||||||||||||||||||||||||
| result.word_timings.emplace_back(); | ||||||||||||||||||||||||||||||||||
| WordTiming& word = result.word_timings.back(); | ||||||||||||||||||||||||||||||||||
| word.word = token_text; | ||||||||||||||||||||||||||||||||||
| word.start_time_ms = token_data.t0 * 10.0; | ||||||||||||||||||||||||||||||||||
| word.end_time_ms = token_data.t1 * 10.0; | ||||||||||||||||||||||||||||||||||
| word.confidence = token_data.p; | ||||||||||||||||||||||||||||||||||
| result.word_timings.push_back(word); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -547,22 +553,59 @@ std::vector<std::string> WhisperCppSTT::get_supported_languages() const { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| std::vector<float> WhisperCppSTT::resample_to_16khz(const std::vector<float>& samples, | ||||||||||||||||||||||||||||||||||
| int source_rate) { | ||||||||||||||||||||||||||||||||||
| if (source_rate == WHISPER_SAMPLE_RATE) { | ||||||||||||||||||||||||||||||||||
| if (source_rate == WHISPER_SAMPLE_RATE || samples.empty()) { | ||||||||||||||||||||||||||||||||||
| return samples; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const double ratio = static_cast<double>(WHISPER_SAMPLE_RATE) / source_rate; | ||||||||||||||||||||||||||||||||||
| const size_t output_size = static_cast<size_t>(samples.size() * ratio); | ||||||||||||||||||||||||||||||||||
| const double step = static_cast<double>(source_rate) / WHISPER_SAMPLE_RATE; | ||||||||||||||||||||||||||||||||||
| const size_t output_size = static_cast<size_t>(samples.size() / step); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| std::vector<float> output; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line with trailing whitespace after declaration
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: sdk/runanywhere-commons/src/backends/whispercpp/whispercpp_backend.cpp
Line: 564:564
Comment:
Blank line with trailing whitespace after declaration
```suggestion
std::vector<float> output;
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (source_rate % WHISPER_SAMPLE_RATE == 0) { | ||||||||||||||||||||||||||||||||||
| int stride = source_rate / WHISPER_SAMPLE_RATE; | ||||||||||||||||||||||||||||||||||
| output.resize(samples.size() / stride); | ||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < output.size(); ++i) { | ||||||||||||||||||||||||||||||||||
| output[i] = samples[i * stride]; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return output; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| if (source_rate % WHISPER_SAMPLE_RATE == 0) { | |
| int stride = source_rate / WHISPER_SAMPLE_RATE; | |
| output.resize(samples.size() / stride); | |
| for (size_t i = 0; i < output.size(); ++i) { | |
| output[i] = samples[i * stride]; | |
| } | |
| return output; | |
| } | |
| if (source_rate % WHISPER_SAMPLE_RATE == 0) { | |
| int stride = source_rate / WHISPER_SAMPLE_RATE; | |
| output.resize(samples.size() / stride); | |
| for (size_t i = 0; i < output.size(); ++i) { | |
| output[i] = samples[i * stride]; | |
| } | |
| return output; | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: sdk/runanywhere-commons/src/backends/whispercpp/whispercpp_backend.cpp
Line: 566:573
Comment:
Indentation inconsistent with surrounding code - missing 4 spaces
```suggestion
if (source_rate % WHISPER_SAMPLE_RATE == 0) {
int stride = source_rate / WHISPER_SAMPLE_RATE;
output.resize(samples.size() / stride);
for (size_t i = 0; i < output.size(); ++i) {
output[i] = samples[i * stride];
}
return output;
}
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looping with push_back after exact size calculation reduces performance benefit of vectorization optimization. Consider using indexed writes with pre-sized vector since output_size is known upfront
Prompt To Fix With AI
This is a comment left during a code review.
Path: sdk/runanywhere-commons/src/backends/whispercpp/whispercpp_backend.cpp
Line: 597:609
Comment:
Looping with `push_back` after exact size calculation reduces performance benefit of vectorization optimization. Consider using indexed writes with pre-sized vector since `output_size` is known upfront
How can I resolve this? If you propose a fix, please make it concise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace after reserve call
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI