Skip to content

Commit 702064a

Browse files
felrockiThalay
authored andcommitted
Change temp file name for server application (ggml-org#1535)
Avoid issue of removing file if it exists in the current working directory
1 parent 1707d4c commit 702064a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

examples/server/server.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,21 +453,23 @@ int main(int argc, char ** argv) {
453453
std::vector<float> pcmf32; // mono-channel F32 PCM
454454
std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM
455455

456-
// write file to temporary file
457-
std::ofstream temp_file{filename, std::ios::binary};
456+
// write to temporary file
457+
const std::string temp_filename = "whisper_server_temp_file.wav";
458+
std::ofstream temp_file{temp_filename, std::ios::binary};
458459
temp_file << audio_file.content;
459460
temp_file.close();
460461

461462
// read wav content into pcmf32
462-
if (!::read_wav(filename, pcmf32, pcmf32s, params.diarize)) {
463-
fprintf(stderr, "error: failed to read WAV file '%s'\n", filename.c_str());
463+
if (!::read_wav(temp_filename, pcmf32, pcmf32s, params.diarize)) {
464+
fprintf(stderr, "error: failed to read WAV file '%s'\n", temp_filename.c_str());
464465
const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
465466
res.set_content(error_resp, "application/json");
467+
std::remove(temp_filename.c_str());
466468
whisper_mutex.unlock();
467469
return;
468470
}
469471
// remove temp file
470-
std::remove(filename.c_str());
472+
std::remove(temp_filename.c_str());
471473

472474
printf("Successfully loaded %s\n", filename.c_str());
473475

0 commit comments

Comments
 (0)