vakodiya's picture
Update app.py
4f68f2f verified
raw
history blame
1.26 kB
import streamlit as st
import numpy as np
import io
import wave
import requests
from audio_to_text import audio_to_text
from streamlit_mic_recorder import mic_recorder
# Initialize Streamlit app layout
st.title("Microphone Input in Streamlit")
# Record audio
audio = mic_recorder(
start_prompt="Start recording",
stop_prompt="Stop recording",
just_once=False,
use_container_width=True
)
# Check if audio is recorded
if audio:
st.audio(audio['bytes'], format='audio/wav')
byte_data=audio['bytes']
# Get raw audio data from the frame
audio_data = byte_data.to_ndarray().astype(np.int16)
# Convert audio to text
transcription = audio_to_text(audio_data)
# Display the transcription
st.write("Transcription:", transcription)
API_URL = "https://eaa0-34-74-179-199.ngrok-free.app/generate"
# Optionally, send the transcription to an API
headers = {
"Content-Type": "application/json"
}
payload = {
"prompt": transcription
}
response = requests.post(API_URL, json=payload, headers=headers)
if response.status_code == 200:
st.write("Assistant:", response.json())
else:
st.write("Error:", response.status_code, response.text)