Repository: ggerganov/whisper.cpp
File: examples/server/server.cpp (C++)

Code before:
            const std::string error_resp = "{\"error\":\"no 'file' field in the request\"}";
            res.set_content(error_resp, "application/json");
            whisper_mutex.unlock();
            return;
        }
        auto audio_file = req.get_file_value("file");

        // check non-required fields
        get_req_parameters(req, params);

        std::string filename{audio_file.filename};
        printf("Received request: %s\n", filename.c_str());

        // audio arrays
        std::vector<float> pcmf32;               // mono-channel F32 PCM
        std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM

        // write to temporary file
        const std::string temp_filename = "whisper_server_temp_file.wav";
        std::ofstream temp_file{temp_filename, std::ios::binary};
        temp_file << audio_file.content;
        temp_file.close();

        // if file is not wav, convert to wav
        
        if(sparams.ffmpeg_converter) {
            std::string error_resp = "{\"error\":\"Failed to execute ffmpeg command.\"}";
            bool isConverted = convert_to_WAV(temp_filename, error_resp);
            if(!isConverted) {
                res.set_content(error_resp, "application/json");
                whisper_mutex.unlock();
                return;
            }
        }

        // read wav content into pcmf32
        if (!::read_wav(temp_filename, pcmf32, pcmf32s, params.diarize)) {
            fprintf(stderr, "error: failed to read WAV file '%s'\n", temp_filename.c_str());
            const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
            res.set_content(error_resp, "application/json");
            std::remove(temp_filename.c_str());
            whisper_mutex.unlock();
            return;
        }
        // remove temp file
        std::remove(temp_filename.c_str());

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

        // print system information
        {

Review comment (suggestion):
```suggestion
        if (sparams.ffmpeg_converter) {
```

Code after:
            const std::string error_resp = "{\"error\":\"no 'file' field in the request\"}";
            res.set_content(error_resp, "application/json");
            whisper_mutex.unlock();
            return;
        }
        auto audio_file = req.get_file_value("file");

        // check non-required fields
        get_req_parameters(req, params);

        std::string filename{audio_file.filename};
        printf("Received request: %s\n", filename.c_str());

        // audio arrays
        std::vector<float> pcmf32;               // mono-channel F32 PCM
        std::vector<std::vector<float>> pcmf32s; // stereo-channel F32 PCM

        // write to temporary file
        const std::string temp_filename = "whisper_server_temp_file.wav";
        std::ofstream temp_file{temp_filename, std::ios::binary};
        temp_file << audio_file.content;
        temp_file.close();

        // if file is not wav, convert to wav
        
        if (sparams.ffmpeg_converter) {
            std::string error_resp = "{\"error\":\"Failed to execute ffmpeg command.\"}";
            const bool is_converted = convert_to_wav(temp_filename, error_resp);
            if (!is_converted) {
                res.set_content(error_resp, "application/json");
                whisper_mutex.unlock();
                return;
            }
        }

        // read wav content into pcmf32
        if (!::read_wav(temp_filename, pcmf32, pcmf32s, params.diarize)) {
            fprintf(stderr, "error: failed to read WAV file '%s'\n", temp_filename.c_str());
            const std::string error_resp = "{\"error\":\"failed to read WAV file\"}";
            res.set_content(error_resp, "application/json");
            std::remove(temp_filename.c_str());
            whisper_mutex.unlock();
            return;
        }
        // remove temp file
        std::remove(temp_filename.c_str());

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

        // print system information
        {