Skip to content

Commit ae4f80c

Browse files
committed
fix merging mistakes.
1 parent 6f54482 commit ae4f80c

File tree

5 files changed

+476
-34
lines changed

5 files changed

+476
-34
lines changed

cmake/build-info.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ endif()
4242
if(MSVC)
4343
set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
4444
set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
45+
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
46+
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
4547
else()
4648
execute_process(
4749
COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}

examples/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ if (WHISPER_SDL2)
8888
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
8989
endif()
9090

91-
<<<<<<<<< Temporary merge branch 1
92-
add_library(json_cpp INTERFACE)
93-
target_include_directories(json_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
94-
95-
9691

9792
# Get all propreties that cmake supports
9893
if(NOT CMAKE_PROPERTY_LIST)
@@ -230,7 +225,7 @@ elseif(CMAKE_JS_VERSION)
230225
set_target_properties(addon.node PROPERTIES FOLDER "examples")
231226
else()
232227
add_subdirectory(main)
233-
<<<<<<<<< Temporary merge branch 1
228+
234229
if (WHISPER_SDL2)
235230
#set_target_properties(stream PROPERTIES FOLDER "examples")
236231
endif (WHISPER_SDL2)
@@ -249,12 +244,11 @@ if (WHISPER_SDL2)
249244
#set_target_properties(talk PROPERTIES FOLDER "examples")
250245
#set_target_properties(talk-llama PROPERTIES FOLDER "examples")
251246
set_target_properties(main PROPERTIES FOLDER "examples")
247+
endif (WHISPER_SDL2)
252248
if (WHISPER_SDL2)
253249
add_subdirectory(stream)
254250
set_target_properties(stream PROPERTIES FOLDER "examples")
255251
endif (WHISPER_SDL2)
256-
add_subdirectory(stream-portaudio)
257-
set_target_properties(stream-portaudio PROPERTIES FOLDER "examples")
258252
if (WHISPER_SDL2)
259253
add_subdirectory(command)
260254
set_target_properties(command PROPERTIES FOLDER "examples")

examples/common-portaudio.h

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ using namespace std;
3333
#include <vector>
3434
#include <mutex>
3535
#include <condition_variable>
36-
#include <cstring> // 用于memcpy
36+
#include <cstring> // memcpy
3737

3838

3939
template <typename T>
4040
class CircularQueue {
4141
public:
4242
explicit CircularQueue(size_t capacity) : capacity_(capacity), queue_(capacity){}
4343

44-
// 阻塞连续块写入
4544
public:
4645
bool enqueue(const void* pdata, size_t blockSize) {
4746
int retry = 2;
@@ -51,35 +50,30 @@ class CircularQueue {
5150
//std::cout << readIndex_ << " " << writeIndex_ << std::endl;
5251
//std::cout << size_ << std::endl;
5352

54-
// 使用lambda函数来判断容量是否足够
5553
auto isCapacityEnough = [&]() {
56-
return ((capacity_-size_) >= blockSize);
54+
return ((capacity_ - size_) >= blockSize);
5755
};
5856

59-
6057
volatile bool status = conditionVariable_.wait_for(lock, std::chrono::microseconds(100), isCapacityEnough);
61-
6258
if (status == false)
6359
{
6460
lock.unlock();
6561
std::cout << "[enqueue] timeout" << std::endl;
6662
return false;
6763
}
6864

69-
// 执行连续写入
7065
size_t remainingSpace = capacity_ - writeIndex_;
7166
size_t dataSize = blockSize * sizeof(T);
7267

7368
if (dataSize <= remainingSpace * sizeof(T)) {
74-
// 数据不跨越队列尾部
7569
std::memcpy(&queue_[writeIndex_], pdata, dataSize);
76-
} else {
77-
// 数据跨越队列尾部
70+
}
71+
else {
7872
size_t firstPartSize = remainingSpace * sizeof(T);
79-
std::memcpy(&queue_[writeIndex_], (char *)pdata, firstPartSize);
73+
std::memcpy(&queue_[writeIndex_], (char*)pdata, firstPartSize);
8074

8175
size_t secondPartSize = dataSize - firstPartSize;
82-
std::memcpy(&queue_[0], (char *)((T *)pdata + remainingSpace), secondPartSize);
76+
std::memcpy(&queue_[0], (char*)((T*)pdata + remainingSpace), secondPartSize);
8377
}
8478

8579
writeIndex_ = (writeIndex_ + blockSize) % capacity_;
@@ -89,20 +83,18 @@ class CircularQueue {
8983
//std::cout << "After enqueue" << std::endl;
9084
//std::cout << readIndex_ << " " << writeIndex_ << std::endl;
9185
//std::cout << size_ << std::endl;
92-
conditionVariable_.notify_one(); // 通知读取线程数据已经可用
86+
conditionVariable_.notify_one();
9387

9488
return true;
95-
}
89+
};
9690

97-
// 阻塞连续块读出
9891
bool dequeue(void* pdata, size_t blockSize) {
9992
std::unique_lock<std::mutex> lock(mutex_);
10093

10194
//std::cout << "Before dequeue" << std::endl;
10295
//std::cout << readIndex_ << " " << writeIndex_ << std::endl;
10396
//std::cout << size_ << std::endl;
10497

105-
// 使用lambda函数来判断容量是否足够
10698
auto isCapacityEnough = [&]() {
10799
return size_ >= blockSize;
108100
};
@@ -120,10 +112,8 @@ class CircularQueue {
120112
size_t dataSize = blockSize * sizeof(T);
121113

122114
if (dataSize <= remainingData * sizeof(T)) {
123-
// 数据不跨越队列尾部
124115
std::memcpy((char *)pdata, &queue_[readIndex_], dataSize);
125116
} else {
126-
// 数据跨越队列尾部
127117
size_t firstPartSize = remainingData * sizeof(T);
128118
std::memcpy((char *)pdata, &queue_[readIndex_], firstPartSize);
129119

@@ -138,24 +128,21 @@ class CircularQueue {
138128
//std::cout << "After dequeue" << std::endl;
139129
//std::cout << readIndex_ << " " << writeIndex_ << std::endl;
140130
//std::cout << size_ << std::endl;
141-
conditionVariable_.notify_one(); // 通知写入线程队列有足够空间
131+
conditionVariable_.notify_one();
142132

143133
return true;
144134
}
145135

146-
// 判断队列是否为空
147136
bool empty() {
148137
std::unique_lock<std::mutex> lock(mutex_);
149138
return size_ == 0;
150139
}
151140

152-
// 判断队列是否已满
153141
bool full() {
154142
std::unique_lock<std::mutex> lock(mutex_);
155143
return size_ == capacity_;
156144
}
157145

158-
// 获取队列中元素的数量
159146
size_t size() {
160147
std::unique_lock<std::mutex> lock(mutex_);
161148
return size_;

examples/main/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ struct whisper_params {
5252
bool detect_language = false;
5353
bool diarize = false;
5454
bool tinydiarize = false;
55-
bool split_on_word = false;
5655
bool no_fallback = false;
5756
bool output_txt = false;
5857
bool output_vtt = false;
@@ -141,7 +140,6 @@ static bool whisper_params_parse(int argc, char ** argv, whisper_params & params
141140
else if (arg == "-tr" || arg == "--translate") { params.translate = true; }
142141
else if (arg == "-di" || arg == "--diarize") { params.diarize = true; }
143142
else if (arg == "-tdrz" || arg == "--tinydiarize") { params.tinydiarize = true; }
144-
else if (arg == "-sow" || arg == "--split-on-word") { params.split_on_word = true; }
145143
else if (arg == "-nf" || arg == "--no-fallback") { params.no_fallback = true; }
146144
else if (arg == "-otxt" || arg == "--output-txt") { params.output_txt = true; }
147145
else if (arg == "-ovtt" || arg == "--output-vtt") { params.output_vtt = true; }
@@ -195,7 +193,6 @@ static void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params
195193
fprintf(stderr, " -d N, --duration N [%-7d] duration of audio to process in milliseconds\n", params.duration_ms);
196194
fprintf(stderr, " -mc N, --max-context N [%-7d] maximum number of text context tokens to store\n", params.max_context);
197195
fprintf(stderr, " -ml N, --max-len N [%-7d] maximum segment length in characters\n", params.max_len);
198-
fprintf(stderr, " -sow, --split-on-word [%-7s] split on word rather than on token\n", params.split_on_word ? "true" : "false");
199196
fprintf(stderr, " -bo N, --best-of N [%-7d] number of best candidates to keep\n", params.best_of);
200197
fprintf(stderr, " -bs N, --beam-size N [%-7d] beam size for beam search\n", params.beam_size);
201198
fprintf(stderr, " -ac N, --audio-ctx N [%-7d] audio context size (0 - all)\n", params.audio_ctx);
@@ -1101,7 +1098,6 @@ int main(int argc, char ** argv) {
11011098
wparams.token_timestamps = params.output_wts || params.output_jsn_full || params.max_len > 0;
11021099
wparams.thold_pt = params.word_thold;
11031100
wparams.max_len = params.output_wts && params.max_len == 0 ? 60 : params.max_len;
1104-
wparams.split_on_word = params.split_on_word;
11051101
wparams.audio_ctx = params.audio_ctx;
11061102

11071103
wparams.debug_mode = params.debug_mode;

0 commit comments

Comments
 (0)