|
|
from transformers import pipeline |
|
|
import scipy.io.wavfile |
|
|
import asyncio |
|
|
|
|
|
|
|
|
synthesiser = pipeline("text-to-audio", model="../music") |
|
|
|
|
|
async def generate_audio(text): |
|
|
"""Generate audio asynchronously""" |
|
|
loop = asyncio.get_event_loop() |
|
|
music = await loop.run_in_executor( |
|
|
None, |
|
|
lambda: synthesiser(text, forward_params={"do_sample": True}) |
|
|
) |
|
|
|
|
|
output_file = "melody.wav" |
|
|
scipy.io.wavfile.write(output_file, rate=music["sampling_rate"], data=music["audio"]) |
|
|
print(f"Saved: {output_file}") |
|
|
|
|
|
|
|
|
asyncio.run(generate_audio("pop romance melody")) |
|
|
|
|
|
|