@@ -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
114115static 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