Download usage.py from datasetsANDmodels/melody-maker-from_description: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/datasetsANDmodels/melody-maker-from_description/resolve/main/usage.py
- Command line
-
hf download hf://datasetsANDmodels/melody-maker-from_description/usage.py
-
curl -L -o usage.py https://huggingface.co/datasetsANDmodels/melody-maker-from_description/resolve/main/usage.py
646 Bytes
| from transformers import pipeline | |
| import scipy.io.wavfile | |
| import asyncio | |
| # Use a valid text-to-audio model (example: bark) | |
| 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}") | |
| # Run async | |
| asyncio.run(generate_audio("pop romance melody")) | |