Fralet commited on
Commit
240b689
·
verified ·
1 Parent(s): 0cd4364

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -1,6 +1,6 @@
1
- from transformers import pipeline, TFAutoModelForCausalLM, AutoTokenizer
2
- import soundfile as sf
3
- import torch
4
 
5
  # Initialize the translation pipeline for Russian to English
6
  translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
@@ -20,14 +20,9 @@ summary = summarizer(translation, max_length=140, min_length=110, do_sample=Fals
20
 
21
  print("Summary: ", summary)
22
 
23
- tokenizer = AutoTokenizer.from_pretrained("facebook/fastspeech2-en-ljspeech")
24
- model = TFAutoModelForCausalLM.from_pretrained("facebook/fastspeech2-en-ljspeech")
25
-
26
- inputs = tokenizer(summary, return_tensors="tf")
27
-
28
- # Generate speech
29
- with torch.no_grad():
30
- logits = model.generate(**inputs)
31
 
32
- # Save the audio
33
- sf.write('output_audio.wav', logits.numpy(), samplerate=16000)
 
 
 
1
+ from transformers import pipeline
2
+
3
+ tts = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")
4
 
5
  # Initialize the translation pipeline for Russian to English
6
  translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
 
20
 
21
  print("Summary: ", summary)
22
 
23
+ speech = tts(summary)
 
 
 
 
 
 
 
24
 
25
+ # The output is a list of PyTorch tensors containing the audio data
26
+ # Let's save the first (and only) audio sample to a file
27
+ with open("output1.wav", "wb") as f:
28
+ f.write(speech[0]["file"].read())