How to export to audio in following code(from a model)?

Viewed 26

I am trying to execute the following code in this document. https://github.com/magenta/midi-ddsp. The one I am trying is the Advance Usage part. However, the synthesized_audio_changed in this doc is just an array, and I can't find the way about how to export the audio.

Moreover, it shows Generating: 0%| | 0/2712 [00:00<?, ?it/s] in the beginning. But my code is as same as theirs, so I am not sure whether it is the system incompatible problem (maybe it could just run in Colab?). Here is my code, and I just copy half of them, because the upper part is similar with the later part, just the difference of the parameters.

import numpy as np
import tensorflow as tf
from midi_ddsp.utils.midi_synthesis_utils import synthesize_mono_midi, conditioning_df_to_audio
from midi_ddsp.utils.inference_utils import get_process_group
from midi_ddsp.midi_ddsp_synthesize import load_pretrained_model
from midi_ddsp.data_handling.instrument_name_utils import INST_NAME_TO_ID_DICT

# -----MIDI Synthesis-----
midi_file = '/Users/midi-ddsp/midi_example/ode_to_joy.mid'
# Load pre-trained model
synthesis_generator, expression_generator = load_pretrained_model()
# Synthesize with violin:
instrument_name = 'violin'
instrument_id = INST_NAME_TO_ID_DICT[instrument_name]
# Run model prediction
midi_audio, midi_control_params, midi_synth_params, conditioning_df = synthesize_mono_midi(synthesis_generator,
                                                                                           expression_generator,
                                                                                           midi_file, instrument_id,
                                                                                           output_dir=None)

synthesized_audio = midi_audio  # The synthesized audio

# -----Adjust note expression controls and re-synthesize-----

# Make all notes weak vibrato:
conditioning_df_changed = conditioning_df.copy()
note_vibrato = conditioning_df_changed['vibrato']

conditioning_df_changed['vibrato'] = (conditioning_df['vibrato'].values) * 0.1
# Re-synthesize
midi_audio_changed, midi_control_params_changed, midi_synth_params_changed = conditioning_df_to_audio(
  synthesis_generator, conditioning_df_changed, tf.constant([instrument_id]))

synthesized_audio_changed = midi_audio_changed  # The synthesized audio
0 Answers
Related