@@ -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,7 @@ 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+ return file.good ();
112112}
113113
114114static void fill_hann_window (int length, bool periodic, float * output) {
@@ -536,6 +536,7 @@ static std::string audio_data_from_speaker(json speaker, const outetts_version t
536536int main (int argc, char ** argv) {
537537 common_params params;
538538
539+ params.out_file = " output.wav" ;
539540 params.prompt = " " ;
540541
541542 params.n_predict = 4096 ;
@@ -1060,8 +1061,6 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
10601061 }
10611062 #endif
10621063
1063- const std::string fname = " output.wav" ;
1064-
10651064 const int n_sr = 24000 ; // sampling rate
10661065
10671066 // zero out first 0.25 seconds
@@ -1072,11 +1071,15 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
10721071 LOG_INF (" %s: time for spectral ops: %.3f ms\n " , __func__, (ggml_time_us () - t_spec_start) / 1000 .0f );
10731072 LOG_INF (" %s: total time: %.3f ms\n " , __func__, (ggml_time_us () - t_main_start) / 1000 .0f );
10741073
1075- save_wav16 (fname, audio, n_sr) ;
1074+ int retval = 0 ;
10761075
1077- LOG_INF (" %s: audio written to file '%s'\n " , __func__, fname.c_str ());
1076+ if (save_wav16 (params.out_file , audio, n_sr)) {
1077+ LOG_INF (" %s: audio written to file '%s'\n " , __func__, params.out_file .c_str ());
1078+ } else {
1079+ retval = ENOENT;
1080+ }
10781081
10791082 llama_backend_free ();
10801083
1081- return 0 ;
1084+ return retval ;
10821085}
0 commit comments