-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhisper_example.cpp
More file actions
80 lines (68 loc) · 2.83 KB
/
whisper_example.cpp
File metadata and controls
80 lines (68 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (C) 2025 Eddy SDK
// SPDX-License-Identifier: Apache-2.0
#include "eddy/pipelines/whisper_pipeline.hpp"
#include <iostream>
#include <iomanip>
#include <exception>
int main(int argc, char* argv[]) {
try {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <MODEL_DIR> <WAV_FILE> [DEVICE] [LANGUAGE]" << std::endl;
std::cerr << "Example: " << argv[0] << " ./models/whisper-v3-turbo ./audio.wav NPU en" << std::endl;
return 1;
}
std::string model_path = argv[1];
std::string wav_file = argv[2];
std::string device = argc > 3 ? argv[3] : "NPU";
std::string language = argc > 4 ? argv[4] : "en";
std::cout << "=== Eddy Whisper Example ===" << std::endl;
std::cout << "Model: " << model_path << std::endl;
std::cout << "Audio: " << wav_file << std::endl;
std::cout << "Device: " << device << std::endl;
std::cout << "Language: " << language << std::endl;
std::cout << std::endl;
// Configure Whisper pipeline
eddy::WhisperConfig config;
config.model_path = model_path;
config.device = device;
config.language = language;
config.task = "transcribe";
config.return_timestamps = true;
config.enable_cache = true;
config.cache_dir = "./cache";
// Create pipeline
std::cout << "Creating Whisper pipeline..." << std::endl;
eddy::WhisperPipeline pipeline(config);
std::cout << std::endl;
// Transcribe
std::cout << "Transcribing audio..." << std::endl;
auto result = pipeline.transcribe(wav_file);
std::cout << std::endl;
// Print results
std::cout << "=== Transcription Result ===" << std::endl;
std::cout << "Text: " << result.text << std::endl;
std::cout << "Confidence: " << std::fixed << std::setprecision(2)
<< (result.confidence * 100.0f) << "%" << std::endl;
std::cout << "Inference Time: " << std::fixed << std::setprecision(2)
<< result.inference_duration_ms << " ms" << std::endl;
std::cout << std::endl;
// Print timestamps if available
if (!result.chunks.empty()) {
std::cout << "=== Timestamps ===" << std::endl;
for (const auto& chunk : result.chunks) {
std::cout << "[" << std::fixed << std::setprecision(2)
<< chunk.start_ts << " -> ";
if (chunk.end_ts >= 0) {
std::cout << chunk.end_ts;
} else {
std::cout << "?";
}
std::cout << "] " << chunk.text << std::endl;
}
}
return 0;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
}