Merge pull request #2 from Turijon/feature/save-uploaded-audio
Add option to keep input audio.
This commit is contained in:
commit
df2f56baa3
|
|
@ -50,6 +50,7 @@ static void parakeet_print_usage(int /*argc*/, char ** argv, const parakeet_para
|
||||||
fprintf(stderr, " --request-path PATH, [%-7s] Request path prefix\n", sparams.request_path.c_str());
|
fprintf(stderr, " --request-path PATH, [%-7s] Request path prefix\n", sparams.request_path.c_str());
|
||||||
fprintf(stderr, " --inference-path PATH, [%-7s] Inference endpoint path\n", sparams.inference_path.c_str());
|
fprintf(stderr, " --inference-path PATH, [%-7s] Inference endpoint path\n", sparams.inference_path.c_str());
|
||||||
fprintf(stderr, " --convert, [%-7s] Convert audio to WAV via ffmpeg\n", sparams.ffmpeg_converter ? "true" : "false");
|
fprintf(stderr, " --convert, [%-7s] Convert audio to WAV via ffmpeg\n", sparams.ffmpeg_converter ? "true" : "false");
|
||||||
|
fprintf(stderr, " --keep-input-audio, [%-7s] Keep input audio in --tmp-dir\n", sparams.keep_input_audio ? "true" : "false");
|
||||||
fprintf(stderr, " --tmp-dir PATH, [%-7s] Temporary directory for converted files\n", sparams.tmp_dir.c_str());
|
fprintf(stderr, " --tmp-dir PATH, [%-7s] Temporary directory for converted files\n", sparams.tmp_dir.c_str());
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
@ -78,6 +79,7 @@ static bool parakeet_params_parse(int argc, char ** argv, parakeet_params & para
|
||||||
else if (arg == "--request-path") { sparams.request_path = argv[++i]; }
|
else if (arg == "--request-path") { sparams.request_path = argv[++i]; }
|
||||||
else if (arg == "--inference-path") { sparams.inference_path = argv[++i]; }
|
else if (arg == "--inference-path") { sparams.inference_path = argv[++i]; }
|
||||||
else if (arg == "--convert") { sparams.ffmpeg_converter = true; }
|
else if (arg == "--convert") { sparams.ffmpeg_converter = true; }
|
||||||
|
else if (arg == "--keep-input-audio") { sparams.keep_input_audio = true; }
|
||||||
else if (arg == "--tmp-dir") { sparams.tmp_dir = argv[++i]; }
|
else if (arg == "--tmp-dir") { sparams.tmp_dir = argv[++i]; }
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
||||||
|
|
@ -253,12 +255,17 @@ int main(int argc, char ** argv) {
|
||||||
std::vector<float> pcmf32;
|
std::vector<float> pcmf32;
|
||||||
std::vector<std::vector<float>> pcmf32s;
|
std::vector<std::vector<float>> pcmf32s;
|
||||||
|
|
||||||
if (sparams.ffmpeg_converter) {
|
std::string temp_filename;
|
||||||
const std::string temp_filename = generate_temp_filename(sparams.tmp_dir, "parakeet-server", ".wav");
|
|
||||||
std::ofstream temp_file{temp_filename, std::ios::binary};
|
|
||||||
temp_file << audio_file.content;
|
|
||||||
temp_file.close();
|
|
||||||
|
|
||||||
|
if (sparams.keep_input_audio || sparams.ffmpeg_converter) {
|
||||||
|
temp_filename = generate_temp_filename(sparams.tmp_dir, "parakeet-server", ".wav");
|
||||||
|
|
||||||
|
std::ofstream temp_file{temp_filename, std::ios::binary};
|
||||||
|
temp_file.write(audio_file.content.data(),
|
||||||
|
static_cast<std::streamsize>(audio_file.content.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sparams.ffmpeg_converter) {
|
||||||
std::string error_resp;
|
std::string error_resp;
|
||||||
if (!convert_to_wav(temp_filename, error_resp, false)) {
|
if (!convert_to_wav(temp_filename, error_resp, false)) {
|
||||||
res.status = 500;
|
res.status = 500;
|
||||||
|
|
@ -270,10 +277,11 @@ int main(int argc, char ** argv) {
|
||||||
fprintf(stderr, "error: failed to read WAV file '%s'\n", temp_filename.c_str());
|
fprintf(stderr, "error: failed to read WAV file '%s'\n", temp_filename.c_str());
|
||||||
res.status = 400;
|
res.status = 400;
|
||||||
res.set_content("{\"error\":\"failed to read WAV file\"}", "application/json");
|
res.set_content("{\"error\":\"failed to read WAV file\"}", "application/json");
|
||||||
std::remove(temp_filename.c_str());
|
if (!sparams.keep_input_audio) {
|
||||||
|
std::remove(temp_filename.c_str());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::remove(temp_filename.c_str());
|
|
||||||
} else {
|
} else {
|
||||||
if (!::read_audio_data(audio_file.content.data(), audio_file.content.size(), pcmf32, pcmf32s, false)) {
|
if (!::read_audio_data(audio_file.content.data(), audio_file.content.size(), pcmf32, pcmf32s, false)) {
|
||||||
fprintf(stderr, "error: failed to read audio data\n");
|
fprintf(stderr, "error: failed to read audio data\n");
|
||||||
|
|
@ -283,6 +291,10 @@ int main(int argc, char ** argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sparams.keep_input_audio) {
|
||||||
|
std::remove(temp_filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
printf("Successfully loaded %s\n", filename.c_str());
|
printf("Successfully loaded %s\n", filename.c_str());
|
||||||
|
|
||||||
fprintf(stderr, "%s: processing '%s' (%d samples, %.1f sec), %d threads ...\n",
|
fprintf(stderr, "%s: processing '%s' (%d samples, %.1f sec), %d threads ...\n",
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ struct server_params {
|
||||||
int32_t write_timeout = 600;
|
int32_t write_timeout = 600;
|
||||||
|
|
||||||
bool ffmpeg_converter = false;
|
bool ffmpeg_converter = false;
|
||||||
|
bool keep_input_audio = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct segment_token {
|
struct segment_token {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue