musicgen-large / test.py
onurio's picture
use list for JSON serialization
db2e732
raw
history blame contribute delete
549 Bytes
from handler import EndpointHandler
import soundfile as sf
import numpy as np
# init handler
my_handler = EndpointHandler(path=".")
# prepare sample payload
payload = {"inputs": "Lowfi hiphop with deep bass"}
# test the handler
pred=my_handler(payload)
audio_data = np.array(pred["audio_data"], dtype=np.float32)
sampling_rate = pred["sampling_rate"]
# Write the audio data to a WAV file
output_file_path = "output.wav" # Specify the file path
sf.write(output_file_path, audio_data, sampling_rate)
print("Audio file saved successfully.")