Spaces:
Runtime error
Runtime error
Commit
·
9d0e9c8
1
Parent(s):
fdba7fc
add tts model
Browse files
app.py
CHANGED
|
@@ -75,6 +75,38 @@ from langchain.schema import (
|
|
| 75 |
LLMResult
|
| 76 |
)
|
| 77 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
class GPTRemote(LLM):
|
| 80 |
n: int
|
|
|
|
| 75 |
LLMResult
|
| 76 |
)
|
| 77 |
import time
|
| 78 |
+
from datasets import load_dataset
|
| 79 |
+
|
| 80 |
+
from transformers import pipeline
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 84 |
+
sample = ds[0]["audio"]
|
| 85 |
+
|
| 86 |
+
def speech_to_text_loc(audio):
|
| 87 |
+
device = "cpu"
|
| 88 |
+
pipe = pipeline(
|
| 89 |
+
"automatic-speech-recognition",
|
| 90 |
+
model="openai/whisper-small",
|
| 91 |
+
chunk_length_s=30,
|
| 92 |
+
device=device,
|
| 93 |
+
)
|
| 94 |
+
text = pipe(audio.copy(), batch_size=2)["text"]
|
| 95 |
+
return text
|
| 96 |
+
|
| 97 |
+
print("voice to text loc: ", speech_to_text_loc(sample))
|
| 98 |
+
|
| 99 |
+
def text_to_speech_loc(audio):
|
| 100 |
+
device = "cpu"
|
| 101 |
+
pipe = pipeline(
|
| 102 |
+
"text-to-speech",
|
| 103 |
+
model="microsoft/speecht5_tts",
|
| 104 |
+
device=device,
|
| 105 |
+
)
|
| 106 |
+
text = pipe(audio.copy(), batch_size=2)["text"]
|
| 107 |
+
return text
|
| 108 |
+
|
| 109 |
+
print("text to speech: ", text_to_speech_loc("Good morning."))
|
| 110 |
|
| 111 |
class GPTRemote(LLM):
|
| 112 |
n: int
|