File size: 1,258 Bytes
545ec70
336a7dd
 
 
 
ca7863d
4f68f2f
545ec70
 
 
 
4f68f2f
 
 
 
 
 
 
 
 
 
 
 
336a7dd
6be62b1
336a7dd
ca7863d
f40d803
ca7863d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336a7dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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')
    
    # Get raw audio data from the frame
    audio_data = np.frombuffer(audio['bytes'], dtype=np.int16)

    # Convert audio to text
    transcription = audio_to_text(audio_data,audio['sample_rate'])
    
    # 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)