File size: 554 Bytes
8e6ca7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import AutoProcessor, BarkModel
import torch
import scipy.io.wavfile

# Load model and processor
processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")

# Input text
text = "Hello! This is Bark speaking from Hugging Face."

# Prepare inputs
inputs = processor(text, return_tensors="pt")

# Generate audio
with torch.no_grad():
    audio = model.generate(**inputs)

# Save the waveform
audio = audio.cpu().numpy().squeeze()
scipy.io.wavfile.write("bark_output.wav", rate=22050, data=audio)