unijoh commited on
Commit
8be5187
1 Parent(s): eb4d8fe

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +4 -0
tts.py CHANGED
@@ -1,11 +1,15 @@
1
  import torch
2
  from transformers import SpeechT5ForTextToSpeech, SpeechT5Processor
 
3
 
4
  MODEL_ID = "microsoft/speecht5_tts"
5
  processor = SpeechT5Processor.from_pretrained(MODEL_ID)
6
  model = SpeechT5ForTextToSpeech.from_pretrained(MODEL_ID)
7
 
8
  def synthesize_speech(text):
 
 
 
9
  inputs = processor(text, return_tensors="pt")
10
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
  model.to(device)
 
1
  import torch
2
  from transformers import SpeechT5ForTextToSpeech, SpeechT5Processor
3
+ import sentencepiece
4
 
5
  MODEL_ID = "microsoft/speecht5_tts"
6
  processor = SpeechT5Processor.from_pretrained(MODEL_ID)
7
  model = SpeechT5ForTextToSpeech.from_pretrained(MODEL_ID)
8
 
9
  def synthesize_speech(text):
10
+ if not text:
11
+ return "ERROR: Please provide text for synthesis"
12
+
13
  inputs = processor(text, return_tensors="pt")
14
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
  model.to(device)