Skip to content

Instantly share code, notes, and snippets.

@james-see
Created September 25, 2023 17:03
Show Gist options
  • Save james-see/4cdd9e479e46254371a4d207a674a0e5 to your computer and use it in GitHub Desktop.
Save james-see/4cdd9e479e46254371a4d207a674a0e5 to your computer and use it in GitHub Desktop.
using bark to generate audio from text
from transformers import AutoProcessor, BarkModel
import scipy
processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")
voice_preset = "v2/fr_speaker_2"
inputs = processor("[clears throat] Destroying is an act of creation, it makes room for new things to begin. Fire is the best method. Let the spark ignite your soul.", voice_preset=voice_preset)
audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()
sample_rate = model.generation_config.sample_rate
scipy.io.wavfile.write("destroy_bark_out_fr2.wav", rate=sample_rate, data=audio_array)
# run from terminal with aplay - afplay destroy_bark_out_fr2.wav -r 0.9
@james-see
Copy link
Author

forget me not on how to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment