ylacombe HF staff commited on
Commit
d8ea9c9
β€’
1 Parent(s): a3f055a

Add transformers usage

Browse files

Bark will be added to Transformers pretty soon! It is now time to update the model cars to mention the HF implementation!

Files changed (1) hide show
  1. README.md +57 -3
README.md CHANGED
@@ -38,7 +38,61 @@ Use at your own risk.
38
 
39
  The following is additional information about the models released here.
40
 
41
- ## Model Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  ```python
44
  from bark import SAMPLE_RATE, generate_audio, preload_models
@@ -52,10 +106,10 @@ text_prompt = """
52
  Hello, my name is Suno. And, uh β€” and I like pizza. [laughs]
53
  But I also have other interests such as playing tic tac toe.
54
  """
55
- audio_array = generate_audio(text_prompt)
56
 
57
  # play text in notebook
58
- Audio(audio_array, rate=SAMPLE_RATE)
59
  ```
60
 
61
  [pizza.webm](https://user-images.githubusercontent.com/5068315/230490503-417e688d-5115-4eee-9550-b46a2b465ee3.webm)
 
38
 
39
  The following is additional information about the models released here.
40
 
41
+ ## πŸ€— Transformers Usage
42
+
43
+
44
+ You can run Bark locally with the πŸ€— Transformers library from version 4.31.0 onwards.
45
+
46
+ 1. First install the πŸ€— [Transformers library](https://github.com/huggingface/transformers) from main:
47
+
48
+ ```
49
+ pip install git+https://github.com/huggingface/transformers.git
50
+ ```
51
+
52
+ 2. Run the following Python code to generate speech samples:
53
+
54
+ ```python
55
+ from transformers import AutoProcessor, AutoModel
56
+
57
+
58
+ processor = AutoProcessor.from_pretrained("suno/bark-small")
59
+ model = AutoModel.from_pretrained("suno/bark-small")
60
+
61
+ inputs = processor(
62
+ text=["Hello, my name is Suno. And, uh β€” and I like pizza. [laughs] But I also have other interests such as playing tic tac toe."],
63
+ return_tensors="pt",
64
+ )
65
+
66
+ speech_values = model.generate_speech(**inputs, do_sample=True)
67
+ ```
68
+
69
+ 3. Listen to the speech samples either in an ipynb notebook:
70
+
71
+ ```python
72
+ from IPython.display import Audio
73
+
74
+ sampling_rate = model.config.sample_rate
75
+ Audio(speech_values.cpu().numpy().squeeze(), rate=sampling_rate)
76
+ ```
77
+
78
+ Or save them as a `.wav` file using a third-party library, e.g. `scipy`:
79
+
80
+ ```python
81
+ import scipy
82
+
83
+ sampling_rate = model.config.sample_rate
84
+ scipy.io.wavfile.write("bark_out.wav", rate=sampling_rate, data=speech_values.cpu().numpy().squeeze())
85
+ ```
86
+
87
+ For more details on using the Bark model for inference using the πŸ€— Transformers library, refer to the [Bark docs](https://huggingface.co/docs/transformers/model_doc/bark).
88
+
89
+ ## Suno Usage
90
+
91
+ You can also run Bark locally through the original [Bark library]((https://github.com/suno-ai/bark):
92
+
93
+ 1. First install the [`bark` library](https://github.com/suno-ai/bark)
94
+
95
+ 3. Run the following Python code:
96
 
97
  ```python
98
  from bark import SAMPLE_RATE, generate_audio, preload_models
 
106
  Hello, my name is Suno. And, uh β€” and I like pizza. [laughs]
107
  But I also have other interests such as playing tic tac toe.
108
  """
109
+ speech_array = generate_audio(text_prompt)
110
 
111
  # play text in notebook
112
+ Audio(speech_array, rate=SAMPLE_RATE)
113
  ```
114
 
115
  [pizza.webm](https://user-images.githubusercontent.com/5068315/230490503-417e688d-5115-4eee-9550-b46a2b465ee3.webm)