# filename: elegant_arabic_transcriber.py import streamlit as st import nemo.collections.asr as nemo_asr import soundfile as sf import tempfile import os from pydub import AudioSegment import time # Custom CSS for gloomy elegant styling st.markdown(""" """, unsafe_allow_html=True) SUPPORTED_TYPES = ['wav', 'mp3', 'ogg', 'flac', 'm4a'] # Load NeMo model once @st.cache_resource def load_model(): model = nemo_asr.models.EncDecHybridRNNTCTCBPEModel.from_pretrained( model_name="nvidia/stt_ar_fastconformer_hybrid_large_pcd_v1.0" ) return model model = load_model() # Helper: Convert any audio to 16kHz mono WAV def convert_audio(uploaded_file, target_sample_rate=16000): with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_out: audio = AudioSegment.from_file(uploaded_file) audio = audio.set_frame_rate(target_sample_rate).set_channels(1) audio.export(tmp_out.name, format="wav") return tmp_out.name # App UI st.markdown("""

Arabic Transcriber

Convert speech to text with precision

""", unsafe_allow_html=True) # Main content - single wide column layout st.markdown("""
🔊 Supports WAV, MP3, OGG, FLAC, M4A
⚡ Fast processing with advanced AI
""", unsafe_allow_html=True) uploaded_file = st.file_uploader("Drag and drop audio file here", type=SUPPORTED_TYPES) if uploaded_file is not None: # Convert to 16kHz mono wav with st.spinner("Preparing audio for transcription..."): processed_wav = convert_audio(uploaded_file) # Show audio info data, sample_rate = sf.read(processed_wav) channels = 1 if len(data.shape) == 1 else data.shape[1] duration = len(data) / sample_rate # Show audio player and info st.audio(processed_wav, format="audio/wav") st.markdown("### Audio Details") st.markdown("""
Duration
{:.1f}s
Sample Rate
{} Hz
Channels
{}
""".format(duration, sample_rate, channels), unsafe_allow_html=True) # Transcription if st.button("Transcribe Audio", type="primary"): # Create a progress container progress_container = st.empty() progress_container.markdown("""
Processing audio...
""", unsafe_allow_html=True) time.sleep(0.8) progress_container.markdown("""
Transcribing content...
""", unsafe_allow_html=True) # Actual transcription with st.spinner(""): result = model.transcribe([processed_wav]) transcript = result[0].text # Update progress to complete progress_container.markdown("""
Transcription complete
""", unsafe_allow_html=True) time.sleep(0.5) progress_container.empty() st.markdown("### Transcription Results") st.markdown(f"""
{transcript}
""", unsafe_allow_html=True) # Download button st.download_button("Download Transcript", transcript, file_name="arabic_transcript.txt") # Cleanup os.remove(processed_wav) # Minimal footer st.markdown("---") st.markdown("""

Powered by NeMo ASR and Streamlit | Professional Arabic Transcription Service

©NightPrince | 2025 Arabic Transcriber Pro | All rights reserved

""", unsafe_allow_html=True)