@@ -79,11 +79,11 @@ struct wav_header {
7979 uint32_t data_size;
8080};
8181
82- static void save_wav16 (const std::string & fname, const std::vector<float > & data, int sample_rate) {
82+ static bool save_wav16 (const std::string & fname, const std::vector<float > & data, int sample_rate) {
8383 std::ofstream file (fname, std::ios::binary);
8484 if (!file) {
85- LOG_ERR (" %s: Failed to open file '%s' for writing" , __func__, fname.c_str ());
86- return ;
85+ LOG_ERR (" %s: Failed to open file '%s' for writing. \n " , __func__, fname.c_str ());
86+ return false ;
8787 }
8888
8989 wav_header header;
@@ -100,7 +100,8 @@ static void save_wav16(const std::string & fname, const std::vector<float> & dat
100100 file.write (reinterpret_cast <const char *>(&pcm_sample), sizeof (pcm_sample));
101101 }
102102
103- file.close ();
103+ // file.close();
104+ return file.good ();
104105}
105106
106107static void fill_hann_window (int length, bool periodic, float * output) {
@@ -464,6 +465,8 @@ int main(int argc, char ** argv) {
464465 params.sampling .top_k = 4 ;
465466 params.sampling .samplers = { COMMON_SAMPLER_TYPE_TOP_K, };
466467
468+ params.out_file = params.ttss_outfile ;
469+
467470 if (!common_params_parse (argc, argv, params, LLAMA_EXAMPLE_TTS, print_usage)) {
468471 return 1 ;
469472 }
@@ -951,8 +954,6 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
951954 }
952955 #endif
953956
954- const std::string fname = " output.wav" ;
955-
956957 const int n_sr = 24000 ; // sampling rate
957958
958959 // zero out first 0.25 seconds
@@ -963,11 +964,18 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
963964 LOG_INF (" %s: time for spectral ops: %.3f ms\n " , __func__, (ggml_time_us () - t_spec_start) / 1000 .0f );
964965 LOG_INF (" %s: total time: %.3f ms\n " , __func__, (ggml_time_us () - t_main_start) / 1000 .0f );
965966
966- save_wav16 (fname, audio, n_sr );
967+ int retval ( 0 );
967968
968- LOG_INF (" %s: audio written to file '%s'\n " , __func__, fname.c_str ());
969+ if (save_wav16 (params.out_file , audio, n_sr)) {
970+ LOG_INF (" %s: audio written to file '%s'\n " , __func__, params.out_file .c_str ());
971+ }
972+
973+ else {
974+ retval=ENOENT;
975+ LOG_ERR (" Check path exists, directory write permissions, free disk space.\n " );
976+ }
969977
970978 llama_backend_free ();
971979
972- return 0 ;
980+ return retval ;
973981}
0 commit comments