xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
11.08k stars 684 forks source link

Add utils : save_audio_to_wav #680

Closed Th3G33k closed 5 months ago

Th3G33k commented 5 months ago

Example use :

const synthesizer = await pipeline('text-to-speech', 'Xenova/mms-tts-eng');
const output = await synthesizer('Hello, my dog is cute');
save_audio_to_wav(output.audio, output.sampling_rate, "audio.wav")
xenova commented 5 months ago

Thanks for this! 🤗 Could you provide a reference for where this code was adapted from? Another thing which should be updated is that this should work if running from node.js.

Also, it might even be a good idea to wrap the output of these pipelines into a Audio class, which has a .save(path) method. This will simplify the usage a lot, and will align well with the RawImage class.

const synthesizer = await pipeline('text-to-speech', 'Xenova/mms-tts-eng');
const output = await synthesizer('Hello, my dog is cute');
output.save("audio.wav");