Skip to content

Commit c0d6409

Browse files
author
litongmacos
committed
add json
1 parent 3c24e0e commit c0d6409

File tree

6 files changed

+98
-11
lines changed

6 files changed

+98
-11
lines changed

resources/json/transcription01.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"transcription": [
3+
{
4+
"timestamps": {
5+
"from": "00:00:00,000",
6+
"to": "00:00:30,000"
7+
},
8+
"offsets": {
9+
"from": 0,
10+
"to": 30000
11+
},
12+
"token": {
13+
"text": "[_BEG_]",
14+
"id": 50363,
15+
"confidence": 0.655302,
16+
"t0": 0,
17+
"t1": 0
18+
},
19+
"token": {
20+
"text": " Thank",
21+
"id": 6952,
22+
"confidence": 0.673538,
23+
"t0": 0,
24+
"t1": 124
25+
},
26+
"token": {
27+
"text": " you",
28+
"id": 345,
29+
"confidence": 0.931985,
30+
"t0": 124,
31+
"t1": 200
32+
},
33+
"token": {
34+
"text": ".",
35+
"id": 13,
36+
"confidence": 0.826669,
37+
"t0": 200,
38+
"t1": 260
39+
},
40+
"token": {
41+
"text": "[_TT_130]",
42+
"id": 50493,
43+
"confidence": 0.0699378,
44+
"t0": 260,
45+
"t1": 3000
46+
},
47+
"token": {
48+
"text": "<|endoftext|>",
49+
"id": 50256,
50+
"confidence": 0.993674,
51+
"t0": 3000,
52+
"t1": 3000
53+
},
54+
"text": "[_BEG_] Thank you.[_TT_130]<|endoftext|>"
55+
}
56+
]
57+
}

resources/json/whisper_local.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"systeminfo": "AVX = 0 | AVX2 = 0 | AVX512 = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | METAL = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | SSSE3 = 0 | VSX = 0 | CUDA = 0 | COREML = 1 | OPENVINO = 0 | ",
3+
"model": {
4+
"type": "base",
5+
"multilingual": false,
6+
"vocab": 51864,
7+
"audio": {
8+
"ctx": 1500,
9+
"state": 512,
10+
"head": 8,
11+
"layer": 6
12+
},
13+
"text": {
14+
"ctx": 448,
15+
"state": 512,
16+
"head": 8,
17+
"layer": 6
18+
},
19+
"mels": 80,
20+
"ftype": 1
21+
},
22+
"params": {
23+
"model": "models/ggml-base.en.bin",
24+
"language": "en",
25+
"translate": false
26+
}
27+
}

stream_components_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace stream_components {
4646

4747
bool tinydiarize = false;
4848
bool diarize = false;
49+
bool use_gpu = true;
4950

5051
std::string language = "en";
5152
std::string model = "models/ggml-base.en.bin";

stream_components_service.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ using namespace stream_components;
55

66
// -- WhisperService --
77

8-
WhisperService::WhisperService(
9-
const struct service_params &server_params,
10-
const struct audio_params &audio_params) :
11-
server_params(server_params),
12-
audio_params(audio_params),
13-
ctx(whisper_init_from_file(server_params.model.c_str())) {
8+
WhisperService::WhisperService(const struct service_params &server_params,
9+
const struct audio_params &audio_params,
10+
const struct whisper_context_params &cparams)
11+
: server_params(server_params),
12+
audio_params(audio_params),
13+
ctx(whisper_init_from_file_with_params(server_params.model.c_str(), cparams)) {
1414
{
1515
fprintf(stderr, "\n");
1616
if (!whisper_is_multilingual(ctx)) {

stream_components_service.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef WHISPER_STREAM_COMPONENTS_SERVER_H
22
#define WHISPER_STREAM_COMPONENTS_SERVER_H
3+
34
#include <vector>
45
#include <whisper.h>
56
#include "stream_components_params.h"
@@ -12,11 +13,12 @@ namespace stream_components {
1213
/**
1314
* Encapsulates the Whisper service.
1415
*/
15-
class WhisperService {
16+
class WhisperService {
1617
public:
1718
WhisperService(
1819
const struct service_params &server_params,
19-
const struct audio_params &audio_params);
20+
const struct audio_params &audio_params,
21+
const struct whisper_context_params &cparams);
2022

2123
~WhisperService();
2224

stream_local.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ int main(int argc, char **argv) {
113113
stream_components::LocalSDLMicrophone microphone(params.audio);
114114

115115
// Instantiate the service
116-
stream_components::WhisperService whisperService(params.service, params.audio);
116+
struct whisper_context_params cparams;
117+
cparams.use_gpu = params.service.use_gpu;
118+
stream_components::WhisperService whisperService(params.service, params.audio,cparams);
117119

118120
// Print the 'header'...
119121
WhisperStreamOutput::to_json(std::cout, params.service, whisperService.ctx);
@@ -133,13 +135,11 @@ int main(int argc, char **argv) {
133135

134136
// get the whisper output
135137
const WhisperOutputPtr &outputPtr = whisperService.process(pcmf32.data(), pcmf32.size());
136-
137138
// write the output as json to stdout (for this example)
138139
if (outputPtr) {
139140
outputPtr->transcription_to_json(std::cout);
140141
}
141142
}
142-
143143
std::cout << "EXITED MAIN LOOP" << std::endl;
144144
return 0;
145145
}

0 commit comments

Comments
 (0)