Skip to content

Commit 4f97726

Browse files
author
litongmacos
committed
output segments
1 parent c0d6409 commit 4f97726

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

stream_components_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace stream_components {
1818
int32_t n_samples_keep = 0;
1919
int32_t n_samples_len = 0;
2020
int32_t n_samples_30s = 0;
21-
bool use_vad = false;
21+
bool use_vad = true;
2222

2323
float vad_thold = 0.6f;
2424
float freq_thold = 100.0f;

stream_components_service.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ WhisperService::~WhisperService() {
4141
whisper_free(ctx);
4242
}
4343

44-
WhisperOutputPtr WhisperService::process(const float *samples, int sample_count) {
44+
bool WhisperService::process(const float *samples, int sample_count) {
4545
whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
4646

4747
wparams.print_progress = false;
@@ -70,7 +70,7 @@ WhisperOutputPtr WhisperService::process(const float *samples, int sample_count)
7070

7171
// *** Run the actual inference!!! ***
7272
if (whisper_full(ctx, wparams, samples, sample_count) != 0) {
73-
return nullptr;
73+
return false;
7474
}
7575

7676
// Now sure whether n_iter and n_new_line should have ever been there...
@@ -96,8 +96,5 @@ WhisperOutputPtr WhisperService::process(const float *samples, int sample_count)
9696
}
9797
}
9898
}
99-
100-
auto r = std::make_shared<WhisperStreamOutput>(ctx, server_params);
101-
102-
return r;
99+
return true;
103100
}

stream_components_service.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ namespace stream_components {
2222

2323
~WhisperService();
2424

25-
WhisperOutputPtr process(
26-
const float *samples,
27-
int size);
25+
bool process(const float *samples,int size);
2826

2927
service_params server_params;
3028
audio_params audio_params;

stream_local.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "stream_components_params.h"
44
#include "stream_components_output.h"
55
#include "stream_components_service.h"
6+
//#include "json.hpp"
67

78
using namespace stream_components;
89

@@ -101,6 +102,8 @@ int main(int argc, char **argv) {
101102

102103
// Compute derived parameters
103104
params.initialize();
105+
//output params
106+
printf("vad:%d\n", params.audio.use_vad);
104107

105108
// Check parameters
106109
if (params.service.language != "auto" && whisper_lang_id(params.service.language.c_str()) == -1) {
@@ -115,7 +118,7 @@ int main(int argc, char **argv) {
115118
// Instantiate the service
116119
struct whisper_context_params cparams;
117120
cparams.use_gpu = params.service.use_gpu;
118-
stream_components::WhisperService whisperService(params.service, params.audio,cparams);
121+
stream_components::WhisperService whisperService(params.service, params.audio, cparams);
119122

120123
// Print the 'header'...
121124
WhisperStreamOutput::to_json(std::cout, params.service, whisperService.ctx);
@@ -133,12 +136,27 @@ int main(int argc, char **argv) {
133136
// get next microphone section
134137
auto pcmf32 = microphone.get_next();
135138

139+
// process
140+
bool isOk = whisperService.process(pcmf32.data(), pcmf32.size());
141+
printf("isOk:%d\n", isOk);
136142
// get the whisper output
137-
const WhisperOutputPtr &outputPtr = whisperService.process(pcmf32.data(), pcmf32.size());
138-
// write the output as json to stdout (for this example)
139-
if (outputPtr) {
140-
outputPtr->transcription_to_json(std::cout);
143+
if (isOk) {
144+
// WhisperOutputPtr outputPtr = std::make_shared<WhisperStreamOutput>(whisperService.ctx, params.service);
145+
// // write the output as json to stdout (for this example)
146+
// if (outputPtr) {
147+
// outputPtr->transcription_to_json(std::cout);
148+
// }
149+
const int n_segments = whisper_full_n_segments(whisperService.ctx);
150+
printf("n_segments:%d\n", n_segments);
151+
for (int i = 0; i < n_segments; ++i) {
152+
const char *text = whisper_full_get_segment_text(whisperService.ctx, i);
153+
const int64_t t0 = whisper_full_get_segment_t0(whisperService.ctx, i);
154+
const int64_t t1 = whisper_full_get_segment_t1(whisperService.ctx, i);
155+
printf("%lld-->%lld:%s\n", t0, t1, text);
156+
}
157+
141158
}
159+
142160
}
143161
std::cout << "EXITED MAIN LOOP" << std::endl;
144162
return 0;

0 commit comments

Comments
 (0)