refactor: Add VAD configuration accessors to Config class
This commit is contained in:
parent
49f9cb906e
commit
aac5602722
@ -52,10 +52,9 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
std::cerr << "[Config] File opened successfully" << std::endl;
|
std::cerr << "[Config] File opened successfully" << std::endl;
|
||||||
|
|
||||||
json config_json;
|
|
||||||
try {
|
try {
|
||||||
std::cerr << "[Config] About to parse JSON..." << std::endl;
|
std::cerr << "[Config] About to parse JSON..." << std::endl;
|
||||||
config_file >> config_json;
|
config_file >> config_;
|
||||||
std::cerr << "[Config] JSON parsed successfully" << std::endl;
|
std::cerr << "[Config] JSON parsed successfully" << std::endl;
|
||||||
} catch (const json::parse_error& e) {
|
} catch (const json::parse_error& e) {
|
||||||
std::cerr << "Error parsing config.json: " << e.what() << std::endl;
|
std::cerr << "Error parsing config.json: " << e.what() << std::endl;
|
||||||
@ -66,8 +65,8 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse audio config
|
// Parse audio config
|
||||||
if (config_json.contains("audio")) {
|
if (config_.contains("audio")) {
|
||||||
auto& audio = config_json["audio"];
|
auto& audio = config_["audio"];
|
||||||
audio_config_.sample_rate = audio.value("sample_rate", 16000);
|
audio_config_.sample_rate = audio.value("sample_rate", 16000);
|
||||||
audio_config_.channels = audio.value("channels", 1);
|
audio_config_.channels = audio.value("channels", 1);
|
||||||
audio_config_.chunk_duration_seconds = audio.value("chunk_duration_seconds", 10);
|
audio_config_.chunk_duration_seconds = audio.value("chunk_duration_seconds", 10);
|
||||||
@ -76,8 +75,8 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse whisper config
|
// Parse whisper config
|
||||||
if (config_json.contains("whisper")) {
|
if (config_.contains("whisper")) {
|
||||||
auto& whisper = config_json["whisper"];
|
auto& whisper = config_["whisper"];
|
||||||
whisper_config_.model = whisper.value("model", "whisper-1");
|
whisper_config_.model = whisper.value("model", "whisper-1");
|
||||||
whisper_config_.language = whisper.value("language", "zh");
|
whisper_config_.language = whisper.value("language", "zh");
|
||||||
whisper_config_.temperature = whisper.value("temperature", 0.0f);
|
whisper_config_.temperature = whisper.value("temperature", 0.0f);
|
||||||
@ -87,8 +86,8 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse claude config
|
// Parse claude config
|
||||||
if (config_json.contains("claude")) {
|
if (config_.contains("claude")) {
|
||||||
auto& claude = config_json["claude"];
|
auto& claude = config_["claude"];
|
||||||
claude_config_.model = claude.value("model", "claude-haiku-4-20250514");
|
claude_config_.model = claude.value("model", "claude-haiku-4-20250514");
|
||||||
claude_config_.max_tokens = claude.value("max_tokens", 1024);
|
claude_config_.max_tokens = claude.value("max_tokens", 1024);
|
||||||
claude_config_.temperature = claude.value("temperature", 0.3f);
|
claude_config_.temperature = claude.value("temperature", 0.3f);
|
||||||
@ -96,8 +95,8 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse UI config
|
// Parse UI config
|
||||||
if (config_json.contains("ui")) {
|
if (config_.contains("ui")) {
|
||||||
auto& ui = config_json["ui"];
|
auto& ui = config_["ui"];
|
||||||
ui_config_.window_width = ui.value("window_width", 800);
|
ui_config_.window_width = ui.value("window_width", 800);
|
||||||
ui_config_.window_height = ui.value("window_height", 600);
|
ui_config_.window_height = ui.value("window_height", 600);
|
||||||
ui_config_.font_size = ui.value("font_size", 16);
|
ui_config_.font_size = ui.value("font_size", 16);
|
||||||
@ -105,8 +104,8 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse recording config
|
// Parse recording config
|
||||||
if (config_json.contains("recording")) {
|
if (config_.contains("recording")) {
|
||||||
auto& recording = config_json["recording"];
|
auto& recording = config_["recording"];
|
||||||
recording_config_.save_audio = recording.value("save_audio", true);
|
recording_config_.save_audio = recording.value("save_audio", true);
|
||||||
recording_config_.output_directory = recording.value("output_directory", "./recordings");
|
recording_config_.output_directory = recording.value("output_directory", "./recordings");
|
||||||
}
|
}
|
||||||
@ -114,4 +113,25 @@ bool Config::load(const std::string& config_path, const std::string& env_path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Config::getVadSilenceDurationMs() const {
|
||||||
|
if (config_.contains("vad") && config_["vad"].contains("silence_duration_ms")) {
|
||||||
|
return config_["vad"]["silence_duration_ms"].get<int>();
|
||||||
|
}
|
||||||
|
return 700; // Default from AudioCapture.h:72 (unchanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
int Config::getVadMinSpeechDurationMs() const {
|
||||||
|
if (config_.contains("vad") && config_["vad"].contains("min_speech_duration_ms")) {
|
||||||
|
return config_["vad"]["min_speech_duration_ms"].get<int>();
|
||||||
|
}
|
||||||
|
return 2000; // Default from AudioCapture.h:73 (updated in TASK2)
|
||||||
|
}
|
||||||
|
|
||||||
|
int Config::getVadMaxSpeechDurationMs() const {
|
||||||
|
if (config_.contains("vad") && config_["vad"].contains("max_speech_duration_ms")) {
|
||||||
|
return config_["vad"]["max_speech_duration_ms"].get<int>();
|
||||||
|
}
|
||||||
|
return 30000; // Default from AudioCapture.h:74 (updated in TASK2)
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace secondvoice
|
} // namespace secondvoice
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace secondvoice {
|
namespace secondvoice {
|
||||||
|
|
||||||
@ -55,6 +56,10 @@ public:
|
|||||||
const std::string& getOpenAIKey() const { return openai_key_; }
|
const std::string& getOpenAIKey() const { return openai_key_; }
|
||||||
const std::string& getAnthropicKey() const { return anthropic_key_; }
|
const std::string& getAnthropicKey() const { return anthropic_key_; }
|
||||||
|
|
||||||
|
int getVadSilenceDurationMs() const;
|
||||||
|
int getVadMinSpeechDurationMs() const;
|
||||||
|
int getVadMaxSpeechDurationMs() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config() = default;
|
Config() = default;
|
||||||
Config(const Config&) = delete;
|
Config(const Config&) = delete;
|
||||||
@ -68,6 +73,7 @@ private:
|
|||||||
|
|
||||||
std::string openai_key_;
|
std::string openai_key_;
|
||||||
std::string anthropic_key_;
|
std::string anthropic_key_;
|
||||||
|
nlohmann::json config_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace secondvoice
|
} // namespace secondvoice
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user