Spaces:
Sleeping
Sleeping
Change temp file name for server application (#1535)
Browse filesAvoid issue of removing file if it exists in the current working
directory
examples/server/server.cpp
CHANGED
|
@@ -453,21 +453,23 @@ int main(int argc, char ** argv) {
|
|
| 453 |
std::vector<float> pcmf32; // mono-channel F32 PCM
|
| 454 |
std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM
|
| 455 |
|
| 456 |
-
// write
|
| 457 |
-
std::
|
|
|
|
| 458 |
temp_file << audio_file.content;
|
| 459 |
temp_file.close();
|
| 460 |
|
| 461 |
// read wav content into pcmf32
|
| 462 |
-
if (!::read_wav(
|
| 463 |
-
fprintf(stderr, "error: failed to read WAV file '%s'\n",
|
| 464 |
const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
|
| 465 |
res.set_content(error_resp, "application/json");
|
|
|
|
| 466 |
whisper_mutex.unlock();
|
| 467 |
return;
|
| 468 |
}
|
| 469 |
// remove temp file
|
| 470 |
-
std::remove(
|
| 471 |
|
| 472 |
printf("Successfully loaded %s\n", filename.c_str());
|
| 473 |
|
|
|
|
| 453 |
std::vector<float> pcmf32; // mono-channel F32 PCM
|
| 454 |
std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM
|
| 455 |
|
| 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};
|
| 459 |
temp_file << audio_file.content;
|
| 460 |
temp_file.close();
|
| 461 |
|
| 462 |
// read wav content into pcmf32
|
| 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());
|
| 465 |
const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
|
| 466 |
res.set_content(error_resp, "application/json");
|
| 467 |
+
std::remove(temp_filename.c_str());
|
| 468 |
whisper_mutex.unlock();
|
| 469 |
return;
|
| 470 |
}
|
| 471 |
// remove temp file
|
| 472 |
+
std::remove(temp_filename.c_str());
|
| 473 |
|
| 474 |
printf("Successfully loaded %s\n", filename.c_str());
|
| 475 |
|