Spaces:
Sleeping
Sleeping
File size: 1,295 Bytes
a4f80cf a2356f4 6e89e8b a0e6ca5 a4f80cf a2356f4 a0e6ca5 a2356f4 a0e6ca5 a2356f4 28134a4 a0e6ca5 a2356f4 |
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 |
import streamlit as st
from audiorecorder import audiorecorder
import openai
import os
import wave
import tempfile
# Nastavení klíče API pro OpenAI
openai.api_key = os.environ['OPENAI_API_KEY']
def transcribe(audio_path):
"""
Transkribuje audio soubor pomocí Whisper API.
"""
with open(audio_path, "rb") as audio_file:
response = openai.Audio.transcribe("whisper-1", audio_file)
return response['data']['text']
# Streamlit aplikace
st.title("Audio Transkriptor")
# Nahrávání audia
st.markdown("Nahrajte svůj hlasový záznam.")
audio_data = audiorecorder("Record", "Stop")
# Zpracování a zobrazení transkripce
if audio_data is not None and len(audio_data) > 0:
# Uložení audio dat do dočasného WAV souboru
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
audio_path = tmp_file.name
with wave.open(audio_path, 'wb') as wav_file:
wav_file.setnchannels(1)
wav_file.setsampwidth(2)
wav_file.setframerate(44100)
wav_file.writeframes(audio_data.tobytes())
# Transkripce audia
with st.spinner('Probíhá transkripci...'):
transcript = transcribe(audio_path)
st.text_area("Transkript", value=transcript, height=300)
|