60 lines
1.6 KiB
C
Raw Normal View History

2023-11-25 10:16:48 +02:00
#pragma once
#include "whisper.h"
#include <string>
#include <vector>
2023-11-25 11:34:06 +02:00
#include <memory>
2023-11-25 10:16:48 +02:00
2023-11-25 11:34:06 +02:00
class Chessboard;
class WChess {
2023-11-25 10:16:48 +02:00
public:
2023-11-25 11:34:06 +02:00
using SetStatusCb = void (*)(const std::string &);
using CheckRunningCb = bool (*)();
using GetAudioCb = void (*)(int, std::vector<float> &);
using SetMovesCb = void (*)(const std::string &);
struct callbacks {
SetStatusCb set_status = nullptr;
CheckRunningCb check_running = nullptr;
GetAudioCb get_audio = nullptr;
SetMovesCb set_moves = nullptr;
};
struct settings {
int32_t vad_ms = 2000;
int32_t prompt_ms = 5000;
int32_t command_ms = 4000;
float vad_thold = 0.1f;
float freq_thold = -1.0f;
bool print_energy = false;
};
WChess(
whisper_context * ctx,
const whisper_full_params & wparams,
callbacks cb,
settings s
);
~WChess();
2023-11-25 10:16:48 +02:00
void run();
2023-11-25 11:34:06 +02:00
std::string stringify_board() const;
2023-11-25 10:16:48 +02:00
private:
2023-11-25 11:34:06 +02:00
void get_audio(int ms, std::vector<float>& pcmf32) const;
void set_status(const std::string& msg) const;
void set_moves(const std::string& moves) const;
bool check_running() const;
2023-11-25 10:16:48 +02:00
std::string transcribe(
const std::vector<float> & pcmf32,
float & logprob_min,
float & logprob_sum,
int & n_tokens,
int64_t & t_ms);
2023-11-25 11:34:06 +02:00
2023-11-25 10:16:48 +02:00
whisper_context * m_ctx;
whisper_full_params m_wparams;
2023-11-25 11:34:06 +02:00
const callbacks m_cb;
const settings m_settings;
std::unique_ptr<Chessboard> m_board;
2023-11-25 10:16:48 +02:00
};