@@ -453,21 +453,23 @@ int main(int argc, char ** argv) {
453
453
std::vector<float > pcmf32; // mono-channel F32 PCM
454
454
std::vector<std::vector<float >> pcmf32s; // stereo-channel F32 PCM
455
455
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};
458
459
temp_file << audio_file.content ;
459
460
temp_file.close ();
460
461
461
462
// 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 ());
464
465
const std::string error_resp = " {\" error\" :\" failed to read WAV file\" }" ;
465
466
res.set_content (error_resp, " application/json" );
467
+ std::remove (temp_filename.c_str ());
466
468
whisper_mutex.unlock ();
467
469
return ;
468
470
}
469
471
// remove temp file
470
- std::remove (filename .c_str ());
472
+ std::remove (temp_filename .c_str ());
471
473
472
474
printf (" Successfully loaded %s\n " , filename.c_str ());
473
475
0 commit comments