Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,18 +31,31 @@ def text2story(text):
|
|
| 31 |
# text2audio
|
| 32 |
def text2audio(story_text):
|
| 33 |
|
| 34 |
-
tts_pipeline = pipeline("text-to-speech", model="suno/bark-small")
|
| 35 |
|
| 36 |
-
audio_data = tts_pipeline(story_text)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
audio_buffer = io.BytesIO()
|
| 39 |
-
wavfile.write(audio_buffer, rate=
|
| 40 |
audio_buffer.seek(0)
|
| 41 |
|
| 42 |
-
return {
|
| 43 |
-
'audio': audio_buffer.getvalue(),
|
| 44 |
-
'sampling_rate': audio_data["sampling_rate"]
|
| 45 |
-
}
|
| 46 |
|
| 47 |
|
| 48 |
# program main part
|
|
|
|
| 31 |
# text2audio
|
| 32 |
def text2audio(story_text):
|
| 33 |
|
| 34 |
+
# tts_pipeline = pipeline("text-to-speech", model="suno/bark-small")
|
| 35 |
|
| 36 |
+
# audio_data = tts_pipeline(story_text)
|
| 37 |
|
| 38 |
+
# audio_buffer = io.BytesIO()
|
| 39 |
+
# wavfile.write(audio_buffer, rate=audio_data["sampling_rate"], data=audio_data["audio"])
|
| 40 |
+
# audio_buffer.seek(0)
|
| 41 |
+
|
| 42 |
+
# return {
|
| 43 |
+
# 'audio': audio_buffer.getvalue(),
|
| 44 |
+
# 'sampling_rate': audio_data["sampling_rate"]
|
| 45 |
+
# }
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
inputs = processor(text=story_text, return_tensors="pt")
|
| 49 |
+
with torch.no_grad():
|
| 50 |
+
speech = model.generate(**inputs)
|
| 51 |
+
|
| 52 |
+
audio_data = speech.cpu().numpy().squeeze()
|
| 53 |
+
|
| 54 |
audio_buffer = io.BytesIO()
|
| 55 |
+
wavfile.write(audio_buffer, rate=16000, data=audio_data) # 16kHz 采样率
|
| 56 |
audio_buffer.seek(0)
|
| 57 |
|
| 58 |
+
return {'audio': audio_buffer.getvalue(), 'sampling_rate': 16000}
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
# program main part
|