Spaces:
Sleeping
Sleeping
File size: 1,268 Bytes
fe85304 d8682b4 fe85304 d8682b4 411d6c8 d8682b4 fe85304 411d6c8 fe85304 d8682b4 fe85304 |
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 |
import streamlit as st
import azure.cognitiveservices.speech as speechsdk
# Azure Speech Service credentials
speech_key = "12afe22c558a4f8d8bd28d6a67cdb9b0"
service_region = "westus"
def transcribe_audio(file_path):
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
audio_input = speechsdk.AudioConfig(filename=file_path)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_input)
result = speech_recognizer.recognize_once()
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
return result.text
elif result.reason == speechsdk.ResultReason.NoMatch:
return "No speech could be recognized"
else:
return "Speech recognition canceled: {}".format(result.cancellation_details.reason)
st.title("Chinese Pronunciation Checker")
uploaded_file = st.file_uploader("Choose an audio file", type=["wav", "mp3"])
if uploaded_file is not None:
st.audio(uploaded_file, format="audio/wav")
file_path = f"temp_audio.{uploaded_file.type.split('/')[-1]}"
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
transcript = transcribe_audio(file_path)
st.write("Transcribed Text: ", transcript)
|