File size: 1,407 Bytes
545ec70
336a7dd
 
a205074
336a7dd
 
ca7863d
4f68f2f
545ec70
a205074
 
 
545ec70
 
 
4f68f2f
 
 
 
 
 
 
 
 
 
 
a205074
 
 
 
336a7dd
ca7863d
a205074
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
47
48
49
50
51
import streamlit as st
import numpy as np
import io
import os
import wave
import requests
from audio_to_text import audio_to_text
from streamlit_mic_recorder import mic_recorder

# Get the directory of the current file
current_dir = os.path.dirname(os.path.abspath(__file__))

# 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')
    audio_bytes = audio["bytes"]
    # Save audio in WEBM format
    with open("recorded_audio.webm", "wb") as webm_file:
        webm_file.write(audio_bytes)

    # Convert audio to text
    transcription = audio_to_text("recorded_audio.webm")
    
    # 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)