Skip to content

Commit ddddfd7

Browse files
committed
llama-tts
* enabled optional cmdline argument '-o' on tts to specify an output filename. It defaults to 'output.wav'. * program now returns ENOENT in case of file write failure
1 parent 7ab3643 commit ddddfd7

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# NOTES
2+
NOTES-*
3+
14
# Extensions
25

36
*.a
@@ -33,7 +36,7 @@
3336
.vs/
3437
.vscode/
3538
nppBackup
36-
39+
*.code-workspace
3740

3841
# Coverage
3942

common/arg.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,13 +1872,15 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
18721872
? params.lora_outfile.c_str()
18731873
: ex == LLAMA_EXAMPLE_CVECTOR_GENERATOR
18741874
? params.cvector_outfile.c_str()
1875-
: params.out_file.c_str()),
1875+
: ex == LLAMA_EXAMPLE_TTS
1876+
? params.ttss_outfile.c_str()
1877+
: params.out_file.c_str()),
18761878
[](common_params & params, const std::string & value) {
18771879
params.out_file = value;
18781880
params.cvector_outfile = value;
18791881
params.lora_outfile = value;
18801882
}
1881-
).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA}));
1883+
).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA, LLAMA_EXAMPLE_TTS}));
18821884
add_opt(common_arg(
18831885
{"-ofreq", "--output-frequency"}, "N",
18841886
string_format("output the imatrix every N iterations (default: %d)", params.n_out_freq),

common/common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ struct common_params {
426426

427427
bool spm_infill = false; // suffix/prefix/middle pattern for infill
428428

429-
std::string lora_outfile = "ggml-lora-merged-f16.gguf";
429+
// default output filenames
430+
std::string
431+
lora_outfile = "ggml-lora-merged-f16.gguf",
432+
ttss_outfile = "output.wav";
430433

431434
// batched-bench params
432435
bool batched_bench_output_jsonl = false;

examples/tts/tts.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ struct wav_header {
8787
uint32_t data_size;
8888
};
8989

90-
static void save_wav16(const std::string & fname, const std::vector<float> & data, int sample_rate) {
90+
static bool save_wav16(const std::string & fname, const std::vector<float> & data, int sample_rate) {
9191
std::ofstream file(fname, std::ios::binary);
9292
if (!file) {
93-
LOG_ERR("%s: Failed to open file '%s' for writing", __func__, fname.c_str());
94-
return;
93+
LOG_ERR("%s: Failed to open file '%s' for writing.\n", __func__, fname.c_str());
94+
return false;
9595
}
9696

9797
wav_header header;
@@ -108,7 +108,8 @@ static void save_wav16(const std::string & fname, const std::vector<float> & dat
108108
file.write(reinterpret_cast<const char*>(&pcm_sample), sizeof(pcm_sample));
109109
}
110110

111-
file.close();
111+
//file.close();
112+
return file.good();
112113
}
113114

114115
static void fill_hann_window(int length, bool periodic, float * output) {
@@ -545,6 +546,8 @@ int main(int argc, char ** argv) {
545546
params.sampling.top_k = 4;
546547
params.sampling.samplers = { COMMON_SAMPLER_TYPE_TOP_K, };
547548

549+
params.out_file = params.ttss_outfile;
550+
548551
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_TTS, print_usage)) {
549552
return 1;
550553
}
@@ -1060,8 +1063,6 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
10601063
}
10611064
#endif
10621065

1063-
const std::string fname = "output.wav";
1064-
10651066
const int n_sr = 24000; // sampling rate
10661067

10671068
// zero out first 0.25 seconds
@@ -1072,11 +1073,18 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
10721073
LOG_INF("%s: time for spectral ops: %.3f ms\n", __func__, (ggml_time_us() - t_spec_start) / 1000.0f);
10731074
LOG_INF("%s: total time: %.3f ms\n", __func__, (ggml_time_us() - t_main_start) / 1000.0f);
10741075

1075-
save_wav16(fname, audio, n_sr);
1076+
int retval(0);
10761077

1077-
LOG_INF("%s: audio written to file '%s'\n", __func__, fname.c_str());
1078+
if (save_wav16(params.out_file, audio, n_sr)) {
1079+
LOG_INF("%s: audio written to file '%s'\n", __func__, params.out_file.c_str());
1080+
}
1081+
1082+
else {
1083+
retval=ENOENT;
1084+
LOG_ERR("Check path exists, directory write permissions, free disk space.\n");
1085+
}
10781086

10791087
llama_backend_free();
10801088

1081-
return 0;
1089+
return retval;
10821090
}

0 commit comments

Comments
 (0)