Spaces:
Sleeping
Sleeping
Commit
·
2d5e45b
1
Parent(s):
0643612
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,22 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
from scipy.io.wavfile import write
|
| 5 |
-
import gradio as gr
|
| 6 |
-
import wavio
|
| 7 |
-
|
| 8 |
-
input_file = 'recorded.wav'
|
| 9 |
-
# output_file = 'output_filtered_receiver.wav'
|
| 10 |
-
|
| 11 |
-
low_frequency = 18000
|
| 12 |
-
high_frequency = 19000
|
| 13 |
-
bit_duration = 0.010
|
| 14 |
-
sample_rate = 44100
|
| 15 |
-
amplitude_scaling_factor = 10.0
|
| 16 |
-
|
| 17 |
-
def record(audio):
|
| 18 |
-
"""
|
| 19 |
-
This function records audio and writes it to a .wav file.
|
| 20 |
-
Parameters:
|
| 21 |
-
audio (tuple): A tuple containing the sample rate and the audio data.
|
| 22 |
-
Returns:
|
| 23 |
-
str: A success message if the audio is recorded correctly, otherwise an error message.
|
| 24 |
-
"""
|
| 25 |
-
try:
|
| 26 |
-
# Check if the audio tuple contains exactly two elements
|
| 27 |
-
if len(audio) != 2:
|
| 28 |
-
return f"Error: Expected a tuple with 2 elements, but got {len(audio)}"
|
| 29 |
-
|
| 30 |
-
# Unpack the sample rate and data from the audio tuple
|
| 31 |
-
sr, data = audio
|
| 32 |
-
|
| 33 |
-
# Write the audio data to a .wav file
|
| 34 |
-
wavio.write("recorded.wav", data, sr)
|
| 35 |
-
|
| 36 |
-
# Call the filtered function to apply the bandpass filter to the audio data
|
| 37 |
-
filtered()
|
| 38 |
-
|
| 39 |
-
# Return a success message
|
| 40 |
-
return f"Audio receive correctly"
|
| 41 |
-
except Exception as e:
|
| 42 |
-
# If an error occurs, return an error message
|
| 43 |
-
return f"Error: {str(e)}"
|
| 44 |
-
|
| 45 |
-
with gr.Blocks() as demo:
|
| 46 |
-
btn_record = gr.Button(value="record")
|
| 47 |
-
btn_record.click(fn=record)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
demo.launch()
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
######################## models
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
+
import io
|
| 7 |
+
import tempfile
|
| 8 |
+
import base64
|
| 9 |
+
from audiorecorder import audiorecorder
|
| 10 |
+
from openai import OpenAI
|
| 11 |
+
client = OpenAI()
|
| 12 |
+
st.title("Whisper App")
|
| 13 |
+
audio = audiorecorder("Click to record", "Click to stop recording")
|
| 14 |
+
|
| 15 |
+
if len(audio) > 0:
|
| 16 |
+
temp_dir = tempfile.mkdtemp()
|
| 17 |
+
temp_file_path = os.path.join(temp_dir, 'temp_audio.mp3')
|
| 18 |
+
audio.export(temp_file_path, format="mp3")
|
| 19 |
+
|
| 20 |
|
| 21 |
|
| 22 |
######################## models
|