@@ -79,11 +79,11 @@ struct wav_header {
79
79
uint32_t data_size;
80
80
};
81
81
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) {
83
83
std::ofstream file (fname, std::ios::binary);
84
84
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 ;
87
87
}
88
88
89
89
wav_header header;
@@ -100,7 +100,8 @@ static void save_wav16(const std::string & fname, const std::vector<float> & dat
100
100
file.write (reinterpret_cast <const char *>(&pcm_sample), sizeof (pcm_sample));
101
101
}
102
102
103
- file.close ();
103
+ // file.close();
104
+ return file.good ();
104
105
}
105
106
106
107
static void fill_hann_window (int length, bool periodic, float * output) {
@@ -464,6 +465,8 @@ int main(int argc, char ** argv) {
464
465
params.sampling .top_k = 4 ;
465
466
params.sampling .samplers = { COMMON_SAMPLER_TYPE_TOP_K, };
466
467
468
+ params.out_file = params.ttss_outfile ;
469
+
467
470
if (!common_params_parse (argc, argv, params, LLAMA_EXAMPLE_TTS, print_usage)) {
468
471
return 1 ;
469
472
}
@@ -951,8 +954,6 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
951
954
}
952
955
#endif
953
956
954
- const std::string fname = " output.wav" ;
955
-
956
957
const int n_sr = 24000 ; // sampling rate
957
958
958
959
// zero out first 0.25 seconds
@@ -963,11 +964,18 @@ lovely<|t_0.56|><|code_start|><|634|><|596|><|1766|><|1556|><|1306|><|1285|><|14
963
964
LOG_INF (" %s: time for spectral ops: %.3f ms\n " , __func__, (ggml_time_us () - t_spec_start) / 1000 .0f );
964
965
LOG_INF (" %s: total time: %.3f ms\n " , __func__, (ggml_time_us () - t_main_start) / 1000 .0f );
965
966
966
- save_wav16 (fname, audio, n_sr );
967
+ int retval ( 0 );
967
968
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
+ }
969
977
970
978
llama_backend_free ();
971
979
972
- return 0 ;
980
+ return retval ;
973
981
}
0 commit comments