Spaces:
Running
Running
common : separate whisper sources (#2846)
Browse files* common : separate whisper sources
* examples : add chrono
* examples : add more headers
- examples/CMakeLists.txt +2 -4
- examples/cli/cli.cpp +1 -1
- examples/command/command.cpp +4 -5
- examples/common-whisper.cpp +177 -0
- examples/common-whisper.h +24 -0
- examples/common.cpp +2 -210
- examples/common.h +1 -39
- examples/lsp/lsp.cpp +4 -3
- examples/server/server.cpp +4 -3
- examples/stream/stream.cpp +3 -3
- examples/talk-llama/CMakeLists.txt +1 -4
- examples/talk-llama/talk-llama.cpp +4 -3
- examples/wchess/libwchess/WChess.cpp +1 -1
examples/CMakeLists.txt
CHANGED
|
@@ -14,10 +14,6 @@ if (WHISPER_SDL2)
|
|
| 14 |
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
|
| 15 |
endif()
|
| 16 |
|
| 17 |
-
if (WHISPER_CLBLAST)
|
| 18 |
-
find_package(CLBlast REQUIRED)
|
| 19 |
-
endif()
|
| 20 |
-
|
| 21 |
# common
|
| 22 |
|
| 23 |
set(TARGET common)
|
|
@@ -56,6 +52,8 @@ add_library(${TARGET} STATIC
|
|
| 56 |
common.cpp
|
| 57 |
common-ggml.h
|
| 58 |
common-ggml.cpp
|
|
|
|
|
|
|
| 59 |
grammar-parser.h
|
| 60 |
grammar-parser.cpp
|
| 61 |
${COMMON_SOURCES_FFMPEG}
|
|
|
|
| 14 |
message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}")
|
| 15 |
endif()
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# common
|
| 18 |
|
| 19 |
set(TARGET common)
|
|
|
|
| 52 |
common.cpp
|
| 53 |
common-ggml.h
|
| 54 |
common-ggml.cpp
|
| 55 |
+
common-whisper.h
|
| 56 |
+
common-whisper.cpp
|
| 57 |
grammar-parser.h
|
| 58 |
grammar-parser.cpp
|
| 59 |
${COMMON_SOURCES_FFMPEG}
|
examples/cli/cli.cpp
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
#include "common.h"
|
|
|
|
| 2 |
|
| 3 |
#include "whisper.h"
|
| 4 |
#include "grammar-parser.h"
|
|
@@ -6,7 +7,6 @@
|
|
| 6 |
#include <cmath>
|
| 7 |
#include <fstream>
|
| 8 |
#include <cstdio>
|
| 9 |
-
#include <regex>
|
| 10 |
#include <string>
|
| 11 |
#include <thread>
|
| 12 |
#include <vector>
|
|
|
|
| 1 |
#include "common.h"
|
| 2 |
+
#include "common-whisper.h"
|
| 3 |
|
| 4 |
#include "whisper.h"
|
| 5 |
#include "grammar-parser.h"
|
|
|
|
| 7 |
#include <cmath>
|
| 8 |
#include <fstream>
|
| 9 |
#include <cstdio>
|
|
|
|
| 10 |
#include <string>
|
| 11 |
#include <thread>
|
| 12 |
#include <vector>
|
examples/command/command.cpp
CHANGED
|
@@ -11,16 +11,15 @@
|
|
| 11 |
#include "whisper.h"
|
| 12 |
#include "grammar-parser.h"
|
| 13 |
|
| 14 |
-
#include <
|
| 15 |
-
#include <
|
| 16 |
#include <cstdio>
|
| 17 |
#include <fstream>
|
| 18 |
-
#include <
|
| 19 |
-
#include <
|
| 20 |
#include <string>
|
| 21 |
#include <thread>
|
| 22 |
#include <vector>
|
| 23 |
-
#include <map>
|
| 24 |
|
| 25 |
// command-line parameters
|
| 26 |
struct whisper_params {
|
|
|
|
| 11 |
#include "whisper.h"
|
| 12 |
#include "grammar-parser.h"
|
| 13 |
|
| 14 |
+
#include <algorithm>
|
| 15 |
+
#include <chrono>
|
| 16 |
#include <cstdio>
|
| 17 |
#include <fstream>
|
| 18 |
+
#include <map>
|
| 19 |
+
#include <sstream>
|
| 20 |
#include <string>
|
| 21 |
#include <thread>
|
| 22 |
#include <vector>
|
|
|
|
| 23 |
|
| 24 |
// command-line parameters
|
| 25 |
struct whisper_params {
|
examples/common-whisper.cpp
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define _USE_MATH_DEFINES // for M_PI
|
| 2 |
+
|
| 3 |
+
#include "common-whisper.h"
|
| 4 |
+
|
| 5 |
+
#include "common.h"
|
| 6 |
+
|
| 7 |
+
#include "whisper.h"
|
| 8 |
+
|
| 9 |
+
// third-party utilities
|
| 10 |
+
// use your favorite implementations
|
| 11 |
+
#define STB_VORBIS_HEADER_ONLY
|
| 12 |
+
#include "stb_vorbis.c" /* Enables Vorbis decoding. */
|
| 13 |
+
|
| 14 |
+
#ifdef _WIN32
|
| 15 |
+
#ifndef NOMINMAX
|
| 16 |
+
#define NOMINMAX
|
| 17 |
+
#endif
|
| 18 |
+
#endif
|
| 19 |
+
|
| 20 |
+
#define MA_NO_DEVICE_IO
|
| 21 |
+
#define MA_NO_THREADING
|
| 22 |
+
#define MA_NO_ENCODING
|
| 23 |
+
#define MA_NO_GENERATION
|
| 24 |
+
#define MA_NO_RESOURCE_MANAGER
|
| 25 |
+
#define MA_NO_NODE_GRAPH
|
| 26 |
+
#define MINIAUDIO_IMPLEMENTATION
|
| 27 |
+
#include "miniaudio.h"
|
| 28 |
+
|
| 29 |
+
#if defined(_MSC_VER)
|
| 30 |
+
#pragma warning(disable: 4244 4267) // possible loss of data
|
| 31 |
+
#endif
|
| 32 |
+
|
| 33 |
+
#ifdef _WIN32
|
| 34 |
+
#include <fcntl.h>
|
| 35 |
+
#include <io.h>
|
| 36 |
+
#endif
|
| 37 |
+
|
| 38 |
+
#include <cstring>
|
| 39 |
+
#include <fstream>
|
| 40 |
+
|
| 41 |
+
#ifdef WHISPER_FFMPEG
|
| 42 |
+
// as implemented in ffmpeg_trancode.cpp only embedded in common lib if whisper built with ffmpeg support
|
| 43 |
+
extern bool ffmpeg_decode_audio(const std::string & ifname, std::vector<uint8_t> & wav_data);
|
| 44 |
+
#endif
|
| 45 |
+
|
| 46 |
+
bool read_audio_data(const std::string & fname, std::vector<float>& pcmf32, std::vector<std::vector<float>>& pcmf32s, bool stereo) {
|
| 47 |
+
std::vector<uint8_t> audio_data; // used for pipe input from stdin or ffmpeg decoding output
|
| 48 |
+
|
| 49 |
+
ma_result result;
|
| 50 |
+
ma_decoder_config decoder_config;
|
| 51 |
+
ma_decoder decoder;
|
| 52 |
+
|
| 53 |
+
decoder_config = ma_decoder_config_init(ma_format_f32, stereo ? 2 : 1, WHISPER_SAMPLE_RATE);
|
| 54 |
+
|
| 55 |
+
if (fname == "-") {
|
| 56 |
+
#ifdef _WIN32
|
| 57 |
+
_setmode(_fileno(stdin), _O_BINARY);
|
| 58 |
+
#endif
|
| 59 |
+
|
| 60 |
+
uint8_t buf[1024];
|
| 61 |
+
while (true)
|
| 62 |
+
{
|
| 63 |
+
const size_t n = fread(buf, 1, sizeof(buf), stdin);
|
| 64 |
+
if (n == 0) {
|
| 65 |
+
break;
|
| 66 |
+
}
|
| 67 |
+
audio_data.insert(audio_data.end(), buf, buf + n);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 71 |
+
|
| 72 |
+
fprintf(stderr, "Error: failed to open audio data from stdin (%s)\n", ma_result_description(result));
|
| 73 |
+
|
| 74 |
+
return false;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
fprintf(stderr, "%s: read %zu bytes from stdin\n", __func__, audio_data.size());
|
| 78 |
+
}
|
| 79 |
+
else if (is_wav_buffer(fname)) {
|
| 80 |
+
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 81 |
+
fprintf(stderr, "Error: failed to open audio data from fname buffer (%s)\n", ma_result_description(result));
|
| 82 |
+
|
| 83 |
+
return false;
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
else if ((result = ma_decoder_init_file(fname.c_str(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 87 |
+
#if defined(WHISPER_FFMPEG)
|
| 88 |
+
if (ffmpeg_decode_audio(fname, audio_data) != 0) {
|
| 89 |
+
fprintf(stderr, "error: failed to ffmpeg decode '%s'\n", fname.c_str());
|
| 90 |
+
|
| 91 |
+
return false;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 95 |
+
fprintf(stderr, "error: failed to read audio data as wav (%s)\n", ma_result_description(result));
|
| 96 |
+
|
| 97 |
+
return false;
|
| 98 |
+
}
|
| 99 |
+
#else
|
| 100 |
+
fprintf(stderr, "error: failed to open '%s' file (%s)\n", fname.c_str(), ma_result_description(result));
|
| 101 |
+
|
| 102 |
+
return false;
|
| 103 |
+
#endif
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
ma_uint64 frame_count;
|
| 107 |
+
ma_uint64 frames_read;
|
| 108 |
+
|
| 109 |
+
if ((result = ma_decoder_get_length_in_pcm_frames(&decoder, &frame_count)) != MA_SUCCESS) {
|
| 110 |
+
fprintf(stderr, "error: failed to retrieve the length of the audio data (%s)\n", ma_result_description(result));
|
| 111 |
+
|
| 112 |
+
return false;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
pcmf32.resize(stereo ? frame_count*2 : frame_count);
|
| 116 |
+
|
| 117 |
+
if ((result = ma_decoder_read_pcm_frames(&decoder, pcmf32.data(), frame_count, &frames_read)) != MA_SUCCESS) {
|
| 118 |
+
fprintf(stderr, "error: failed to read the frames of the audio data (%s)\n", ma_result_description(result));
|
| 119 |
+
|
| 120 |
+
return false;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if (stereo) {
|
| 124 |
+
pcmf32s.resize(2);
|
| 125 |
+
pcmf32s[0].resize(frame_count);
|
| 126 |
+
pcmf32s[1].resize(frame_count);
|
| 127 |
+
for (uint64_t i = 0; i < frame_count; i++) {
|
| 128 |
+
pcmf32s[0][i] = pcmf32[2*i];
|
| 129 |
+
pcmf32s[1][i] = pcmf32[2*i + 1];
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
ma_decoder_uninit(&decoder);
|
| 134 |
+
|
| 135 |
+
return true;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// 500 -> 00:05.000
|
| 139 |
+
// 6000 -> 01:00.000
|
| 140 |
+
std::string to_timestamp(int64_t t, bool comma) {
|
| 141 |
+
int64_t msec = t * 10;
|
| 142 |
+
int64_t hr = msec / (1000 * 60 * 60);
|
| 143 |
+
msec = msec - hr * (1000 * 60 * 60);
|
| 144 |
+
int64_t min = msec / (1000 * 60);
|
| 145 |
+
msec = msec - min * (1000 * 60);
|
| 146 |
+
int64_t sec = msec / 1000;
|
| 147 |
+
msec = msec - sec * 1000;
|
| 148 |
+
|
| 149 |
+
char buf[32];
|
| 150 |
+
snprintf(buf, sizeof(buf), "%02d:%02d:%02d%s%03d", (int) hr, (int) min, (int) sec, comma ? "," : ".", (int) msec);
|
| 151 |
+
|
| 152 |
+
return std::string(buf);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
int timestamp_to_sample(int64_t t, int n_samples, int whisper_sample_rate) {
|
| 156 |
+
return std::max(0, std::min((int) n_samples - 1, (int) ((t*whisper_sample_rate)/100)));
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
bool speak_with_file(const std::string & command, const std::string & text, const std::string & path, int voice_id) {
|
| 160 |
+
std::ofstream speak_file(path.c_str());
|
| 161 |
+
if (speak_file.fail()) {
|
| 162 |
+
fprintf(stderr, "%s: failed to open speak_file\n", __func__);
|
| 163 |
+
return false;
|
| 164 |
+
} else {
|
| 165 |
+
speak_file.write(text.c_str(), text.size());
|
| 166 |
+
speak_file.close();
|
| 167 |
+
int ret = system((command + " " + std::to_string(voice_id) + " " + path).c_str());
|
| 168 |
+
if (ret != 0) {
|
| 169 |
+
fprintf(stderr, "%s: failed to speak\n", __func__);
|
| 170 |
+
return false;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
return true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
#undef STB_VORBIS_HEADER_ONLY
|
| 177 |
+
#include "stb_vorbis.c"
|
examples/common-whisper.h
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <vector>
|
| 5 |
+
#include <cstdint>
|
| 6 |
+
|
| 7 |
+
// Read WAV audio file and store the PCM data into pcmf32
|
| 8 |
+
// fname can be a buffer of WAV data instead of a filename
|
| 9 |
+
// The sample rate of the audio must be equal to COMMON_SAMPLE_RATE
|
| 10 |
+
// If stereo flag is set and the audio has 2 channels, the pcmf32s will contain 2 channel PCM
|
| 11 |
+
bool read_audio_data(
|
| 12 |
+
const std::string & fname,
|
| 13 |
+
std::vector<float> & pcmf32,
|
| 14 |
+
std::vector<std::vector<float>> & pcmf32s,
|
| 15 |
+
bool stereo);
|
| 16 |
+
|
| 17 |
+
// convert timestamp to string, 6000 -> 01:00.000
|
| 18 |
+
std::string to_timestamp(int64_t t, bool comma = false);
|
| 19 |
+
|
| 20 |
+
// given a timestamp get the sample
|
| 21 |
+
int timestamp_to_sample(int64_t t, int n_samples, int whisper_sample_rate);
|
| 22 |
+
|
| 23 |
+
// write text to file, and call system("command voice_id file")
|
| 24 |
+
bool speak_with_file(const std::string & command, const std::string & text, const std::string & path, int voice_id);
|
examples/common.cpp
CHANGED
|
@@ -2,26 +2,6 @@
|
|
| 2 |
|
| 3 |
#include "common.h"
|
| 4 |
|
| 5 |
-
// third-party utilities
|
| 6 |
-
// use your favorite implementations
|
| 7 |
-
#define STB_VORBIS_HEADER_ONLY
|
| 8 |
-
#include "stb_vorbis.c" /* Enables Vorbis decoding. */
|
| 9 |
-
|
| 10 |
-
#ifdef _WIN32
|
| 11 |
-
#ifndef NOMINMAX
|
| 12 |
-
#define NOMINMAX
|
| 13 |
-
#endif
|
| 14 |
-
#endif
|
| 15 |
-
|
| 16 |
-
#define MA_NO_DEVICE_IO
|
| 17 |
-
#define MA_NO_THREADING
|
| 18 |
-
#define MA_NO_ENCODING
|
| 19 |
-
#define MA_NO_GENERATION
|
| 20 |
-
#define MA_NO_RESOURCE_MANAGER
|
| 21 |
-
#define MA_NO_NODE_GRAPH
|
| 22 |
-
#define MINIAUDIO_IMPLEMENTATION
|
| 23 |
-
#include "miniaudio.h"
|
| 24 |
-
|
| 25 |
#include <cmath>
|
| 26 |
#include <codecvt>
|
| 27 |
#include <cstring>
|
|
@@ -34,16 +14,6 @@
|
|
| 34 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
| 35 |
#endif
|
| 36 |
|
| 37 |
-
#ifdef _WIN32
|
| 38 |
-
#include <fcntl.h>
|
| 39 |
-
#include <io.h>
|
| 40 |
-
#endif
|
| 41 |
-
|
| 42 |
-
#ifdef WHISPER_FFMPEG
|
| 43 |
-
// as implemented in ffmpeg_trancode.cpp only embedded in common lib if whisper built with ffmpeg support
|
| 44 |
-
extern bool ffmpeg_decode_audio(const std::string & ifname, std::vector<uint8_t> & wav_data);
|
| 45 |
-
#endif
|
| 46 |
-
|
| 47 |
// Function to check if the next argument exists
|
| 48 |
static std::string get_next_arg(int& i, int argc, char** argv, const std::string& flag, gpt_params& params) {
|
| 49 |
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
@@ -654,98 +624,6 @@ bool is_wav_buffer(const std::string buf) {
|
|
| 654 |
return true;
|
| 655 |
}
|
| 656 |
|
| 657 |
-
bool read_audio_data(const std::string & fname, std::vector<float>& pcmf32, std::vector<std::vector<float>>& pcmf32s, bool stereo) {
|
| 658 |
-
std::vector<uint8_t> audio_data; // used for pipe input from stdin or ffmpeg decoding output
|
| 659 |
-
|
| 660 |
-
ma_result result;
|
| 661 |
-
ma_decoder_config decoder_config;
|
| 662 |
-
ma_decoder decoder;
|
| 663 |
-
|
| 664 |
-
decoder_config = ma_decoder_config_init(ma_format_f32, stereo ? 2 : 1, COMMON_SAMPLE_RATE);
|
| 665 |
-
|
| 666 |
-
if (fname == "-") {
|
| 667 |
-
#ifdef _WIN32
|
| 668 |
-
_setmode(_fileno(stdin), _O_BINARY);
|
| 669 |
-
#endif
|
| 670 |
-
|
| 671 |
-
uint8_t buf[1024];
|
| 672 |
-
while (true)
|
| 673 |
-
{
|
| 674 |
-
const size_t n = fread(buf, 1, sizeof(buf), stdin);
|
| 675 |
-
if (n == 0) {
|
| 676 |
-
break;
|
| 677 |
-
}
|
| 678 |
-
audio_data.insert(audio_data.end(), buf, buf + n);
|
| 679 |
-
}
|
| 680 |
-
|
| 681 |
-
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 682 |
-
|
| 683 |
-
fprintf(stderr, "Error: failed to open audio data from stdin (%s)\n", ma_result_description(result));
|
| 684 |
-
|
| 685 |
-
return false;
|
| 686 |
-
}
|
| 687 |
-
|
| 688 |
-
fprintf(stderr, "%s: read %zu bytes from stdin\n", __func__, audio_data.size());
|
| 689 |
-
}
|
| 690 |
-
else if (is_wav_buffer(fname)) {
|
| 691 |
-
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 692 |
-
fprintf(stderr, "Error: failed to open audio data from fname buffer (%s)\n", ma_result_description(result));
|
| 693 |
-
|
| 694 |
-
return false;
|
| 695 |
-
}
|
| 696 |
-
}
|
| 697 |
-
else if ((result = ma_decoder_init_file(fname.c_str(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 698 |
-
#if defined(WHISPER_FFMPEG)
|
| 699 |
-
if (ffmpeg_decode_audio(fname, audio_data) != 0) {
|
| 700 |
-
fprintf(stderr, "error: failed to ffmpeg decode '%s'\n", fname.c_str());
|
| 701 |
-
|
| 702 |
-
return false;
|
| 703 |
-
}
|
| 704 |
-
|
| 705 |
-
if ((result = ma_decoder_init_memory(audio_data.data(), audio_data.size(), &decoder_config, &decoder)) != MA_SUCCESS) {
|
| 706 |
-
fprintf(stderr, "error: failed to read audio data as wav (%s)\n", ma_result_description(result));
|
| 707 |
-
|
| 708 |
-
return false;
|
| 709 |
-
}
|
| 710 |
-
#else
|
| 711 |
-
fprintf(stderr, "error: failed to open '%s' file (%s)\n", fname.c_str(), ma_result_description(result));
|
| 712 |
-
|
| 713 |
-
return false;
|
| 714 |
-
#endif
|
| 715 |
-
}
|
| 716 |
-
|
| 717 |
-
ma_uint64 frame_count;
|
| 718 |
-
ma_uint64 frames_read;
|
| 719 |
-
|
| 720 |
-
if ((result = ma_decoder_get_length_in_pcm_frames(&decoder, &frame_count)) != MA_SUCCESS) {
|
| 721 |
-
fprintf(stderr, "error: failed to retrieve the length of the audio data (%s)\n", ma_result_description(result));
|
| 722 |
-
|
| 723 |
-
return false;
|
| 724 |
-
}
|
| 725 |
-
|
| 726 |
-
pcmf32.resize(stereo ? frame_count*2 : frame_count);
|
| 727 |
-
|
| 728 |
-
if ((result = ma_decoder_read_pcm_frames(&decoder, pcmf32.data(), frame_count, &frames_read)) != MA_SUCCESS) {
|
| 729 |
-
fprintf(stderr, "error: failed to read the frames of the audio data (%s)\n", ma_result_description(result));
|
| 730 |
-
|
| 731 |
-
return false;
|
| 732 |
-
}
|
| 733 |
-
|
| 734 |
-
if (stereo) {
|
| 735 |
-
pcmf32s.resize(2);
|
| 736 |
-
pcmf32s[0].resize(frame_count);
|
| 737 |
-
pcmf32s[1].resize(frame_count);
|
| 738 |
-
for (uint64_t i = 0; i < frame_count; i++) {
|
| 739 |
-
pcmf32s[0][i] = pcmf32[2*i];
|
| 740 |
-
pcmf32s[1][i] = pcmf32[2*i + 1];
|
| 741 |
-
}
|
| 742 |
-
}
|
| 743 |
-
|
| 744 |
-
ma_decoder_uninit(&decoder);
|
| 745 |
-
|
| 746 |
-
return true;
|
| 747 |
-
}
|
| 748 |
-
|
| 749 |
void high_pass_filter(std::vector<float> & data, float cutoff, float sample_rate) {
|
| 750 |
const float rc = 1.0f / (2.0f * M_PI * cutoff);
|
| 751 |
const float dt = 1.0f / sample_rate;
|
|
@@ -821,93 +699,7 @@ float similarity(const std::string & s0, const std::string & s1) {
|
|
| 821 |
return 1.0f - (dist / std::max(s0.size(), s1.size()));
|
| 822 |
}
|
| 823 |
|
| 824 |
-
bool
|
| 825 |
-
|
| 826 |
-
std::string arg = argv[i];
|
| 827 |
-
|
| 828 |
-
if (arg == "-s" || arg == "--seed") {
|
| 829 |
-
params.seed = std::stoi(argv[++i]);
|
| 830 |
-
} else if (arg == "-t" || arg == "--threads") {
|
| 831 |
-
params.n_threads = std::stoi(argv[++i]);
|
| 832 |
-
} else if (arg == "-m" || arg == "--model") {
|
| 833 |
-
params.model = argv[++i];
|
| 834 |
-
} else if (arg == "-i" || arg == "--inp") {
|
| 835 |
-
params.fname_inp = argv[++i];
|
| 836 |
-
} else if (arg == "-o" || arg == "--out") {
|
| 837 |
-
params.fname_out = argv[++i];
|
| 838 |
-
} else if (arg == "-h" || arg == "--help") {
|
| 839 |
-
sam_print_usage(argc, argv, params);
|
| 840 |
-
exit(0);
|
| 841 |
-
} else {
|
| 842 |
-
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
| 843 |
-
sam_print_usage(argc, argv, params);
|
| 844 |
-
exit(0);
|
| 845 |
-
}
|
| 846 |
-
}
|
| 847 |
-
|
| 848 |
-
return true;
|
| 849 |
-
}
|
| 850 |
-
|
| 851 |
-
void sam_print_usage(int /*argc*/, char ** argv, const sam_params & params) {
|
| 852 |
-
fprintf(stderr, "usage: %s [options]\n", argv[0]);
|
| 853 |
-
fprintf(stderr, "\n");
|
| 854 |
-
fprintf(stderr, "options:\n");
|
| 855 |
-
fprintf(stderr, " -h, --help show this help message and exit\n");
|
| 856 |
-
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
|
| 857 |
-
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
| 858 |
-
fprintf(stderr, " -m FNAME, --model FNAME\n");
|
| 859 |
-
fprintf(stderr, " model path (default: %s)\n", params.model.c_str());
|
| 860 |
-
fprintf(stderr, " -i FNAME, --inp FNAME\n");
|
| 861 |
-
fprintf(stderr, " input file (default: %s)\n", params.fname_inp.c_str());
|
| 862 |
-
fprintf(stderr, " -o FNAME, --out FNAME\n");
|
| 863 |
-
fprintf(stderr, " output file (default: %s)\n", params.fname_out.c_str());
|
| 864 |
-
fprintf(stderr, "\n");
|
| 865 |
-
}
|
| 866 |
-
|
| 867 |
-
// 500 -> 00:05.000
|
| 868 |
-
// 6000 -> 01:00.000
|
| 869 |
-
std::string to_timestamp(int64_t t, bool comma) {
|
| 870 |
-
int64_t msec = t * 10;
|
| 871 |
-
int64_t hr = msec / (1000 * 60 * 60);
|
| 872 |
-
msec = msec - hr * (1000 * 60 * 60);
|
| 873 |
-
int64_t min = msec / (1000 * 60);
|
| 874 |
-
msec = msec - min * (1000 * 60);
|
| 875 |
-
int64_t sec = msec / 1000;
|
| 876 |
-
msec = msec - sec * 1000;
|
| 877 |
-
|
| 878 |
-
char buf[32];
|
| 879 |
-
snprintf(buf, sizeof(buf), "%02d:%02d:%02d%s%03d", (int) hr, (int) min, (int) sec, comma ? "," : ".", (int) msec);
|
| 880 |
-
|
| 881 |
-
return std::string(buf);
|
| 882 |
-
}
|
| 883 |
-
|
| 884 |
-
int timestamp_to_sample(int64_t t, int n_samples, int whisper_sample_rate) {
|
| 885 |
-
return std::max(0, std::min((int) n_samples - 1, (int) ((t*whisper_sample_rate)/100)));
|
| 886 |
-
}
|
| 887 |
-
|
| 888 |
-
bool is_file_exist(const char *fileName)
|
| 889 |
-
{
|
| 890 |
-
std::ifstream infile(fileName);
|
| 891 |
return infile.good();
|
| 892 |
}
|
| 893 |
-
|
| 894 |
-
bool speak_with_file(const std::string & command, const std::string & text, const std::string & path, int voice_id)
|
| 895 |
-
{
|
| 896 |
-
std::ofstream speak_file(path.c_str());
|
| 897 |
-
if (speak_file.fail()) {
|
| 898 |
-
fprintf(stderr, "%s: failed to open speak_file\n", __func__);
|
| 899 |
-
return false;
|
| 900 |
-
} else {
|
| 901 |
-
speak_file.write(text.c_str(), text.size());
|
| 902 |
-
speak_file.close();
|
| 903 |
-
int ret = system((command + " " + std::to_string(voice_id) + " " + path).c_str());
|
| 904 |
-
if (ret != 0) {
|
| 905 |
-
fprintf(stderr, "%s: failed to speak\n", __func__);
|
| 906 |
-
return false;
|
| 907 |
-
}
|
| 908 |
-
}
|
| 909 |
-
return true;
|
| 910 |
-
}
|
| 911 |
-
|
| 912 |
-
#undef STB_VORBIS_HEADER_ONLY
|
| 913 |
-
#include "stb_vorbis.c"
|
|
|
|
| 2 |
|
| 3 |
#include "common.h"
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
#include <cmath>
|
| 6 |
#include <codecvt>
|
| 7 |
#include <cstring>
|
|
|
|
| 14 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
| 15 |
#endif
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
// Function to check if the next argument exists
|
| 18 |
static std::string get_next_arg(int& i, int argc, char** argv, const std::string& flag, gpt_params& params) {
|
| 19 |
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
|
|
|
| 624 |
return true;
|
| 625 |
}
|
| 626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
void high_pass_filter(std::vector<float> & data, float cutoff, float sample_rate) {
|
| 628 |
const float rc = 1.0f / (2.0f * M_PI * cutoff);
|
| 629 |
const float dt = 1.0f / sample_rate;
|
|
|
|
| 699 |
return 1.0f - (dist / std::max(s0.size(), s1.size()));
|
| 700 |
}
|
| 701 |
|
| 702 |
+
bool is_file_exist(const char * filename) {
|
| 703 |
+
std::ifstream infile(filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
return infile.good();
|
| 705 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
examples/common.h
CHANGED
|
@@ -11,8 +11,6 @@
|
|
| 11 |
#include <fstream>
|
| 12 |
#include <sstream>
|
| 13 |
|
| 14 |
-
#define COMMON_SAMPLE_RATE 16000
|
| 15 |
-
|
| 16 |
//
|
| 17 |
// GPT CLI argument parsing
|
| 18 |
//
|
|
@@ -139,16 +137,6 @@ gpt_vocab::id gpt_sample_top_k_top_p_repeat(
|
|
| 139 |
// Check if a buffer is a WAV audio file
|
| 140 |
bool is_wav_buffer(const std::string buf);
|
| 141 |
|
| 142 |
-
// Read WAV audio file and store the PCM data into pcmf32
|
| 143 |
-
// fname can be a buffer of WAV data instead of a filename
|
| 144 |
-
// The sample rate of the audio must be equal to COMMON_SAMPLE_RATE
|
| 145 |
-
// If stereo flag is set and the audio has 2 channels, the pcmf32s will contain 2 channel PCM
|
| 146 |
-
bool read_audio_data(
|
| 147 |
-
const std::string & fname,
|
| 148 |
-
std::vector<float> & pcmf32,
|
| 149 |
-
std::vector<std::vector<float>> & pcmf32s,
|
| 150 |
-
bool stereo);
|
| 151 |
-
|
| 152 |
// Write PCM data into WAV audio file
|
| 153 |
class wav_writer {
|
| 154 |
private:
|
|
@@ -266,23 +254,6 @@ bool vad_simple(
|
|
| 266 |
// compute similarity between two strings using Levenshtein distance
|
| 267 |
float similarity(const std::string & s0, const std::string & s1);
|
| 268 |
|
| 269 |
-
//
|
| 270 |
-
// SAM argument parsing
|
| 271 |
-
//
|
| 272 |
-
|
| 273 |
-
struct sam_params {
|
| 274 |
-
int32_t seed = -1; // RNG seed
|
| 275 |
-
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
| 276 |
-
|
| 277 |
-
std::string model = "models/sam-vit-b/ggml-model-f16.bin"; // model path
|
| 278 |
-
std::string fname_inp = "img.jpg";
|
| 279 |
-
std::string fname_out = "img.out";
|
| 280 |
-
};
|
| 281 |
-
|
| 282 |
-
bool sam_params_parse(int argc, char ** argv, sam_params & params);
|
| 283 |
-
|
| 284 |
-
void sam_print_usage(int argc, char ** argv, const sam_params & params);
|
| 285 |
-
|
| 286 |
//
|
| 287 |
// Terminal utils
|
| 288 |
//
|
|
@@ -330,14 +301,5 @@ const std::vector<std::string> k_colors = {
|
|
| 330 |
// Other utils
|
| 331 |
//
|
| 332 |
|
| 333 |
-
// convert timestamp to string, 6000 -> 01:00.000
|
| 334 |
-
std::string to_timestamp(int64_t t, bool comma = false);
|
| 335 |
-
|
| 336 |
-
// given a timestamp get the sample
|
| 337 |
-
int timestamp_to_sample(int64_t t, int n_samples, int whisper_sample_rate);
|
| 338 |
-
|
| 339 |
// check if file exists using ifstream
|
| 340 |
-
bool is_file_exist(const char *
|
| 341 |
-
|
| 342 |
-
// write text to file, and call system("command voice_id file")
|
| 343 |
-
bool speak_with_file(const std::string & command, const std::string & text, const std::string & path, int voice_id);
|
|
|
|
| 11 |
#include <fstream>
|
| 12 |
#include <sstream>
|
| 13 |
|
|
|
|
|
|
|
| 14 |
//
|
| 15 |
// GPT CLI argument parsing
|
| 16 |
//
|
|
|
|
| 137 |
// Check if a buffer is a WAV audio file
|
| 138 |
bool is_wav_buffer(const std::string buf);
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
// Write PCM data into WAV audio file
|
| 141 |
class wav_writer {
|
| 142 |
private:
|
|
|
|
| 254 |
// compute similarity between two strings using Levenshtein distance
|
| 255 |
float similarity(const std::string & s0, const std::string & s1);
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
//
|
| 258 |
// Terminal utils
|
| 259 |
//
|
|
|
|
| 301 |
// Other utils
|
| 302 |
//
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
// check if file exists using ifstream
|
| 305 |
+
bool is_file_exist(const char * filename);
|
|
|
|
|
|
|
|
|
examples/lsp/lsp.cpp
CHANGED
|
@@ -3,14 +3,15 @@
|
|
| 3 |
#include "whisper.h"
|
| 4 |
#include "json.hpp"
|
| 5 |
|
| 6 |
-
#include <iostream>
|
| 7 |
#include <cassert>
|
|
|
|
| 8 |
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
| 9 |
#include <string>
|
| 10 |
#include <thread>
|
| 11 |
#include <vector>
|
| 12 |
-
#include <deque>
|
| 13 |
-
#include <set>
|
| 14 |
|
| 15 |
using json = nlohmann::json;
|
| 16 |
|
|
|
|
| 3 |
#include "whisper.h"
|
| 4 |
#include "json.hpp"
|
| 5 |
|
|
|
|
| 6 |
#include <cassert>
|
| 7 |
+
#include <chrono>
|
| 8 |
#include <cstdio>
|
| 9 |
+
#include <deque>
|
| 10 |
+
#include <iostream>
|
| 11 |
+
#include <set>
|
| 12 |
#include <string>
|
| 13 |
#include <thread>
|
| 14 |
#include <vector>
|
|
|
|
|
|
|
| 15 |
|
| 16 |
using json = nlohmann::json;
|
| 17 |
|
examples/server/server.cpp
CHANGED
|
@@ -1,17 +1,18 @@
|
|
| 1 |
#include "common.h"
|
|
|
|
| 2 |
|
| 3 |
#include "whisper.h"
|
| 4 |
#include "httplib.h"
|
| 5 |
#include "json.hpp"
|
| 6 |
|
|
|
|
| 7 |
#include <cmath>
|
| 8 |
-
#include <fstream>
|
| 9 |
#include <cstdio>
|
|
|
|
|
|
|
| 10 |
#include <string>
|
| 11 |
#include <thread>
|
| 12 |
#include <vector>
|
| 13 |
-
#include <cstring>
|
| 14 |
-
#include <sstream>
|
| 15 |
|
| 16 |
#if defined(_MSC_VER)
|
| 17 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
|
|
|
| 1 |
#include "common.h"
|
| 2 |
+
#include "common-whisper.h"
|
| 3 |
|
| 4 |
#include "whisper.h"
|
| 5 |
#include "httplib.h"
|
| 6 |
#include "json.hpp"
|
| 7 |
|
| 8 |
+
#include <chrono>
|
| 9 |
#include <cmath>
|
|
|
|
| 10 |
#include <cstdio>
|
| 11 |
+
#include <fstream>
|
| 12 |
+
#include <sstream>
|
| 13 |
#include <string>
|
| 14 |
#include <thread>
|
| 15 |
#include <vector>
|
|
|
|
|
|
|
| 16 |
|
| 17 |
#if defined(_MSC_VER)
|
| 18 |
#pragma warning(disable: 4244 4267) // possible loss of data
|
examples/stream/stream.cpp
CHANGED
|
@@ -4,15 +4,15 @@
|
|
| 4 |
//
|
| 5 |
#include "common-sdl.h"
|
| 6 |
#include "common.h"
|
|
|
|
| 7 |
#include "whisper.h"
|
| 8 |
|
| 9 |
-
#include <
|
| 10 |
#include <cstdio>
|
|
|
|
| 11 |
#include <string>
|
| 12 |
#include <thread>
|
| 13 |
#include <vector>
|
| 14 |
-
#include <fstream>
|
| 15 |
-
|
| 16 |
|
| 17 |
// command-line parameters
|
| 18 |
struct whisper_params {
|
|
|
|
| 4 |
//
|
| 5 |
#include "common-sdl.h"
|
| 6 |
#include "common.h"
|
| 7 |
+
#include "common-whisper.h"
|
| 8 |
#include "whisper.h"
|
| 9 |
|
| 10 |
+
#include <chrono>
|
| 11 |
#include <cstdio>
|
| 12 |
+
#include <fstream>
|
| 13 |
#include <string>
|
| 14 |
#include <thread>
|
| 15 |
#include <vector>
|
|
|
|
|
|
|
| 16 |
|
| 17 |
// command-line parameters
|
| 18 |
struct whisper_params {
|
examples/talk-llama/CMakeLists.txt
CHANGED
|
@@ -25,10 +25,7 @@ if (WHISPER_SDL2)
|
|
| 25 |
unicode-data.cpp)
|
| 26 |
target_include_directories(${TARGET} PRIVATE ${SDL2_INCLUDE_DIRS})
|
| 27 |
|
| 28 |
-
|
| 29 |
-
set(CLBLAST_LIBNAME clblast)
|
| 30 |
-
endif ()
|
| 31 |
-
target_link_libraries(${TARGET} PRIVATE common common-sdl whisper ${SDL2_LIBRARIES} ${CLBLAST_LIBNAME} ${CMAKE_THREAD_LIBS_INIT})
|
| 32 |
|
| 33 |
if(WIN32)
|
| 34 |
# It requires Windows 8.1 or later for PrefetchVirtualMemory
|
|
|
|
| 25 |
unicode-data.cpp)
|
| 26 |
target_include_directories(${TARGET} PRIVATE ${SDL2_INCLUDE_DIRS})
|
| 27 |
|
| 28 |
+
target_link_libraries(${TARGET} PRIVATE common common-sdl whisper ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if(WIN32)
|
| 31 |
# It requires Windows 8.1 or later for PrefetchVirtualMemory
|
examples/talk-llama/talk-llama.cpp
CHANGED
|
@@ -3,18 +3,19 @@
|
|
| 3 |
|
| 4 |
#include "common-sdl.h"
|
| 5 |
#include "common.h"
|
|
|
|
| 6 |
#include "whisper.h"
|
| 7 |
#include "llama.h"
|
| 8 |
|
| 9 |
-
#include <
|
| 10 |
#include <cstdio>
|
| 11 |
#include <fstream>
|
| 12 |
#include <regex>
|
|
|
|
|
|
|
| 13 |
#include <string>
|
| 14 |
#include <thread>
|
| 15 |
#include <vector>
|
| 16 |
-
#include <regex>
|
| 17 |
-
#include <sstream>
|
| 18 |
|
| 19 |
static std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::string & text, bool add_bos) {
|
| 20 |
const llama_model * model = llama_get_model(ctx);
|
|
|
|
| 3 |
|
| 4 |
#include "common-sdl.h"
|
| 5 |
#include "common.h"
|
| 6 |
+
#include "common-whisper.h"
|
| 7 |
#include "whisper.h"
|
| 8 |
#include "llama.h"
|
| 9 |
|
| 10 |
+
#include <chrono>
|
| 11 |
#include <cstdio>
|
| 12 |
#include <fstream>
|
| 13 |
#include <regex>
|
| 14 |
+
#include <regex>
|
| 15 |
+
#include <sstream>
|
| 16 |
#include <string>
|
| 17 |
#include <thread>
|
| 18 |
#include <vector>
|
|
|
|
|
|
|
| 19 |
|
| 20 |
static std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::string & text, bool add_bos) {
|
| 21 |
const llama_model * model = llama_get_model(ctx);
|
examples/wchess/libwchess/WChess.cpp
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
#include "Chessboard.h"
|
| 3 |
#include "grammar-parser.h"
|
| 4 |
#include "common.h"
|
| 5 |
-
#include <
|
| 6 |
|
| 7 |
WChess::WChess(whisper_context * ctx,
|
| 8 |
const whisper_full_params & wparams,
|
|
|
|
| 2 |
#include "Chessboard.h"
|
| 3 |
#include "grammar-parser.h"
|
| 4 |
#include "common.h"
|
| 5 |
+
#include <chrono>
|
| 6 |
|
| 7 |
WChess::WChess(whisper_context * ctx,
|
| 8 |
const whisper_full_params & wparams,
|