jcvsalinas commited on
Commit
5992d87
·
verified ·
1 Parent(s): f33917a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -27
app.py CHANGED
@@ -1,28 +1,28 @@
1
- from transformers import pipeline
2
-
3
  import gradio as gr
4
-
5
- asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
6
- classifier = pipeline("text-classification")
7
-
8
- def speech_to_text(speech):
9
- text = asr(speech)["text"]
10
- return text
11
-
12
- def text_to_sentiment(text):
13
- return classifier(text)[0]["label"]
14
-
15
- demo = gr.Blocks()
16
-
17
- with demo:
18
- audio_file = gr.Audio(type="filepath")
19
- text = gr.Textbox()
20
- label = gr.Label()
21
-
22
- b1 = gr.Button("Recognize Speech")
23
- b2 = gr.Button("Classify Sentiment")
24
-
25
- b1.click(speech_to_text, inputs=audio_file, outputs=text)
26
- b2.click(text_to_sentiment, inputs=text, outputs=label)
27
-
28
- demo.launch()
 
 
 
 
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ # This function returns the waveform data to be displayed
6
+ def record_audio(audio):
7
+ if audio is not None:
8
+ data = audio[0] # Extract the audio data from the tuple
9
+ sample_rate = audio[1] # Extract the sample rate
10
+
11
+ # Create a mm plot
12
+ plt.figure(figsize=(10, 4))
13
+ plt.plot(data)
14
+ plt.title("Real-Time Audio Waveform")
15
+ plt.xlabel("Sample Number")
16
+ plt.ylabel("Amplitude")
17
+ plt.grid(True)
18
+ return plt
19
+
20
+ # Define the Gradio interface
21
+ gr.Interface(
22
+ fn=record_audio,
23
+ inputs=gr.Audio(type="numpy"), # Capture audio as numpy array
24
+ outputs="plot", # Output the waveform plot
25
+ live=True, # Enable real-time recording
26
+ title="Real-Time Audio Recording",
27
+ description="Record audio in real time and view the waveform."
28
+ ).launch()