Skip to content

Commit e5dcc9d

Browse files
gmiodicekshitij-sisodia-arm
authored andcommitted
Change default output filename in the audiogen app
- The new default output filename is <prompt>_<seed>.wav Signed-off-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
1 parent fc3118d commit e5dcc9d

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

kleidiai-examples/audiogen/app/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ From there, you can then run the `audiogen` application, which requires just thr
6868
- **CPU Threads (-t)**: The number of CPU threads to use (e.g., `4`)
6969

7070
```bash
71-
./audiogen -m . -p "warm arpeggios on house beats 120BPM with drums effect" -t 4
71+
./audiogen -m $LITERT_MODELS_PATH -p "warm arpeggios on house beats 120BPM with drums effect" -t 4
7272
```
7373

74-
If everything runs successfully, the generated audio will be saved in `.wav` format (`output.wav`) in the `audiogen_app` folder. At this point, you can play it on your laptop or PC.
74+
If everything runs successfully, the generated audio will be saved in `.wav` format (`warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav`) in the `audiogen_app` folder. At this point, you can play it on your laptop or PC.
7575

7676
### Build the audiogen app on Linux® (HOST) or macOS® (HOST) for Android™ (TARGET)
7777

@@ -168,8 +168,8 @@ From there, you can then run the `audiogen` application, which requires just thr
168168
./audiogen -m . -p "warm arpeggios on house beats 120BPM with drums effect" -t 4
169169
```
170170

171-
If everything runs successfully, the generated audio will be saved in `.wav` format (`output.wav`) in the same directory as the `audiogen` binary. At this point, you can then retrieve it using the `adb` tool from a different Terminal and play it on your laptop or PC.
171+
If everything runs successfully, the generated audio will be saved in `.wav` format (`warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav`) in the same directory as the `audiogen` binary. At this point, you can then retrieve it using the `adb` tool from a different Terminal and play it on your laptop or PC.
172172

173173
```bash
174-
adb pull data/local/tmp/output.wav
174+
adb pull data/local/tmp/warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav
175175
```

kleidiai-examples/audiogen/app/audiogen.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
constexpr size_t k_seed_default = 99;
4444
constexpr size_t k_audio_len_sec_default = 10;
4545
constexpr size_t k_num_steps_default = 8;
46-
const std::string k_output_file_default = "output.wav";
4746

4847
// -- Update the tensor index based on your model configuration.
4948
constexpr size_t k_t5_ids_in_idx = 0;
@@ -85,13 +84,23 @@ static void print_usage(const char *name) {
8584
" -s <seed> (Optional) Random seed for reproducibility. Different seeds generate different audio samples (Default: %zu)\n"
8685
" -l <audio_len_sec> (Optional) Length of generated audio (Default: %zu s)\n"
8786
" -n <num_steps> (Optional) Number of steps (Default: %zu)\n"
88-
" -o <output_file> (Optional) Output audio file name (Default: %s)\n"
87+
" -o <output_file> (Optional) Output audio file name (Default: <prompt>_<seed>.wav)\n"
8988
" -h Show this help message\n",
9089
name,
9190
k_seed_default,
9291
k_audio_len_sec_default,
93-
k_num_steps_default,
94-
k_output_file_default.c_str());
92+
k_num_steps_default);
93+
}
94+
95+
static std::string get_filename(std::string prompt, size_t seed) {
96+
// Convert spaces to underscores
97+
std::replace(prompt.begin(), prompt.end(), ' ', '_');
98+
99+
// Convert to lowercase
100+
std::transform(prompt.begin(), prompt.end(), prompt.begin(),
101+
[](unsigned char c) { return std::tolower(c); });
102+
103+
return prompt + "_" + std::to_string(seed) + ".wav";
95104
}
96105

97106
static std::vector<int32_t> convert_prompt_to_ids(const std::string& prompt, const std::string& spiece_model_path) {
@@ -220,7 +229,7 @@ int main(int32_t argc, char** argv) {
220229
std::string prompt = "";
221230
size_t num_threads = 0;
222231
// Optional arguments
223-
std::string output_file = k_output_file_default;
232+
std::string output_file = "";
224233
size_t seed = k_seed_default;
225234
size_t num_steps = k_num_steps_default;
226235
float audio_len_sec = static_cast<float>(k_audio_len_sec_default);
@@ -436,6 +445,11 @@ int main(int32_t argc, char** argv) {
436445
const float* left_ch = autoencoder_out_data;
437446
const float* right_ch = autoencoder_out_data + num_audio_samples;
438447

448+
// If output filename empty -> filename = <prompt>_<seed>.wav
449+
if (output_file.empty()) {
450+
output_file = get_filename(prompt, seed);
451+
}
452+
439453
save_as_wav(output_file.c_str(), left_ch, right_ch, num_audio_samples);
440454

441455
// Save the file

0 commit comments

Comments
 (0)