rdlf commited on
Commit
a741cb6
·
verified ·
1 Parent(s): 68d6ccb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -1,23 +1,20 @@
1
  import streamlit as st
2
  from PIL import Image
3
- from groq import Groq
4
  import os
5
- from transformers import pipeline
6
 
7
  st.image('calamo.png', caption="", use_column_width=False)
8
 
9
- import scipy.io.wavfile
10
-
11
- synthesizer = pipeline("text-to-speech", "suno/bark")
12
-
13
-
14
 
15
  client = Groq(
16
  api_key=os.environ.get("GROQ_API_KEY"),
17
  )
 
18
  # Other content of your app
19
  st.title("plAIn Voice")
20
- # Add more components here
21
 
22
  # Define a function to process the input
23
  def process_text(input_text):
@@ -42,11 +39,13 @@ def process_text(input_text):
42
  model="mixtral-8x7b-32768",
43
  )
44
  return (chat_completion.choices[0].message.content)
 
45
  def generate_audio(input_text):
46
  tts = process_text(input_text)
47
- speech = synthesizer(tts, forward_params={"do_sample": True})
48
- scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"])
49
- return "bark_out.wav"
 
50
 
51
  user_input = st.text_input("Pega un texto para aclararlo y escuchar una lectura.")
52
 
@@ -55,7 +54,4 @@ if st.button('Aclarar'):
55
  st.write("Pega un texto aquí")
56
  else:
57
  speech_file = generate_audio(user_input)
58
- st.audio(speech_file, format='audio/wav')
59
-
60
-
61
-
 
1
  import streamlit as st
2
  from PIL import Image
 
3
  import os
4
+ from openai import OpenAI, Whisper
5
 
6
  st.image('calamo.png', caption="", use_column_width=False)
7
 
8
+ # Initialize OpenAI and Whisper
9
+ openai = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
10
+ whisper = Whisper(openai)
 
 
11
 
12
  client = Groq(
13
  api_key=os.environ.get("GROQ_API_KEY"),
14
  )
15
+
16
  # Other content of your app
17
  st.title("plAIn Voice")
 
18
 
19
  # Define a function to process the input
20
  def process_text(input_text):
 
39
  model="mixtral-8x7b-32768",
40
  )
41
  return (chat_completion.choices[0].message.content)
42
+
43
  def generate_audio(input_text):
44
  tts = process_text(input_text)
45
+ speech = whisper.synthesize(tts)
46
+ with open("whisper_out.wav", "wb") as f:
47
+ f.write(speech.audio)
48
+ return "whisper_out.wav"
49
 
50
  user_input = st.text_input("Pega un texto para aclararlo y escuchar una lectura.")
51
 
 
54
  st.write("Pega un texto aquí")
55
  else:
56
  speech_file = generate_audio(user_input)
57
+ st.audio(speech_file, format='audio/wav')