File size: 1,469 Bytes
ace928d
 
9191a09
ace928d
 
9191a09
ace928d
 
9191a09
 
 
 
 
ace928d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9191a09
ace928d
 
 
 
9191a09
 
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
import json

import streamlit as st
from audiorecorder import audiorecorder
import requests

STT_API_KEY = "gV6KiOm_eDrOisgI9B9hBbcTeNEwYQT4XNLJNLaI6DMk" #see discord
STT_URL = "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/de074216-e340-4d56-b391-406532c98440/v1/recognize" #see discord

st.markdown("<h1 style='text-align: center;'>Tell us how you feel</h1>", unsafe_allow_html=True)

st.write("<h3 style='text-align: center; color: lightSeaGreen;'>we'll generate the insights</h3>", unsafe_allow_html=True)

audio = audiorecorder("Click to record", "Click to stop recording")


if not audio.empty():
    # To play audio in frontend:
    st.audio(audio.export().read())  

    # To save audio to a file, use pydub export method:
    audio.export("audio.flac", format="flac")

    # Convert audio to text

    headers = {
        "Content-Type": "audio/flac"
    }

    with open("audio.flac", "rb") as f:
        response = requests.post(STT_URL, auth=("apikey", STT_API_KEY), headers=headers, files={'audio.flac': f})

    response_json = response.json()
    print(response_json)
    if response_json["results"]:
        response_text = response_json["results"][0]["alternatives"][0]["transcript"]
    else:
        response_text = "No audio detected"
    print(response_text)

    # To get audio properties, use pydub AudioSegment properties:
    st.text_area(label="Output", 
                value=response_text,
                height=300)