From ee65df7982450f20712747d8a3c71dc736eb118c Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 28 Nov 2023 13:37:26 +0200 Subject: [PATCH] wchess : add clear_audio callback --- examples/wchess/CMakeLists.txt | 3 ++- examples/wchess/libwchess/WChess.cpp | 7 +++++++ examples/wchess/libwchess/WChess.h | 3 +++ examples/wchess/wchess.cmd/wchess.cmd.cpp | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/wchess/CMakeLists.txt b/examples/wchess/CMakeLists.txt index 9f2dbb9a..4bbc85ab 100644 --- a/examples/wchess/CMakeLists.txt +++ b/examples/wchess/CMakeLists.txt @@ -1,3 +1,4 @@ +set(CMAKE_CXX_STANDARD 11) add_subdirectory(libwchess) @@ -5,4 +6,4 @@ if (EMSCRIPTEN) add_subdirectory(wchess.wasm) else() add_subdirectory(wchess.cmd) -endif() \ No newline at end of file +endif() diff --git a/examples/wchess/libwchess/WChess.cpp b/examples/wchess/libwchess/WChess.cpp index 9cffd0f3..4725384e 100644 --- a/examples/wchess/libwchess/WChess.cpp +++ b/examples/wchess/libwchess/WChess.cpp @@ -48,6 +48,11 @@ bool WChess::check_running() const { return false; } +bool WChess::clear_audio() const { + if (m_cb.clear_audio) return (*m_cb.clear_audio)(); + return false; +} + void WChess::get_audio(int ms, std::vector& pcmf32) const { if (m_cb.get_audio) (*m_cb.get_audio)(ms, pcmf32); } @@ -195,6 +200,8 @@ void WChess::run() { set_moves(m_board->process(command)); } } + + clear_audio(); } } } diff --git a/examples/wchess/libwchess/WChess.h b/examples/wchess/libwchess/WChess.h index fd019594..994d7a3b 100644 --- a/examples/wchess/libwchess/WChess.h +++ b/examples/wchess/libwchess/WChess.h @@ -12,12 +12,14 @@ public: using CheckRunningCb = bool (*)(); using GetAudioCb = void (*)(int, std::vector &); using SetMovesCb = void (*)(const std::string &); + using CleartAudioCb = bool (*)(); struct callbacks { SetStatusCb set_status = nullptr; CheckRunningCb check_running = nullptr; GetAudioCb get_audio = nullptr; SetMovesCb set_moves = nullptr; + CleartAudioCb clear_audio = nullptr; }; struct settings { @@ -44,6 +46,7 @@ private: void set_status(const std::string& msg) const; void set_moves(const std::string& moves) const; bool check_running() const; + bool clear_audio() const; std::string transcribe( const std::vector & pcmf32, float & logprob_min, diff --git a/examples/wchess/wchess.cmd/wchess.cmd.cpp b/examples/wchess/wchess.cmd/wchess.cmd.cpp index b3b30023..735209a5 100644 --- a/examples/wchess/wchess.cmd/wchess.cmd.cpp +++ b/examples/wchess/wchess.cmd/wchess.cmd.cpp @@ -118,6 +118,10 @@ void get_audio(int ms, std::vector & pcmf32_cur) { g_audio.get(ms, pcmf32_cur); } +bool clear_audio() { + g_audio.clear(); +} + int main(int argc, char ** argv) { whisper_params params; @@ -180,6 +184,7 @@ int main(int argc, char ** argv) { cb.check_running = sdl_poll_events; cb.get_audio = get_audio; cb.set_moves = set_moves; + cb.clear_audio = clear_audio; WChess::settings s; s.vad_ms = 2000;