Add files using upload-large-folder tool
Browse files- .gitattributes +14 -0
- app.py +414 -0
- data_tts/gcloud_tts_sample_1056.wav +3 -0
- data_tts/gcloud_tts_sample_106.wav +3 -0
- data_tts/gcloud_tts_sample_1061.wav +3 -0
- data_tts/gcloud_tts_sample_1063.wav +3 -0
- data_tts/gcloud_tts_sample_1064.wav +3 -0
- data_tts/gcloud_tts_sample_1066.wav +3 -0
- data_tts/gcloud_tts_sample_1068.wav +3 -0
- data_tts/gcloud_tts_sample_1069.wav +3 -0
- data_tts/gcloud_tts_sample_1070.wav +3 -0
- data_tts/gcloud_tts_sample_1071.wav +3 -0
- data_tts/gcloud_tts_sample_1072.wav +3 -0
- data_tts/gcloud_tts_sample_1073.wav +3 -0
- data_tts/gcloud_tts_sample_1075.wav +3 -0
- data_tts/gcloud_tts_sample_1079.wav +3 -0
- data_tts/gcloud_tts_sample_1184.wav +0 -0
- data_tts/gcloud_tts_sample_1185.wav +0 -0
- data_tts/gcloud_tts_sample_1186.wav +0 -0
- data_tts/gcloud_tts_sample_1187.wav +0 -0
- data_tts/gcloud_tts_sample_1188.wav +0 -0
.gitattributes
CHANGED
|
@@ -954,3 +954,17 @@ data_tts/gemini_pro_tts_sample_1546.wav filter=lfs diff=lfs merge=lfs -text
|
|
| 954 |
data_tts/gemini_pro_tts_sample_155.wav filter=lfs diff=lfs merge=lfs -text
|
| 955 |
data_tts/gcloud_tts_sample_1212.wav filter=lfs diff=lfs merge=lfs -text
|
| 956 |
data_tts/gcloud_tts_sample_1217.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 954 |
data_tts/gemini_pro_tts_sample_155.wav filter=lfs diff=lfs merge=lfs -text
|
| 955 |
data_tts/gcloud_tts_sample_1212.wav filter=lfs diff=lfs merge=lfs -text
|
| 956 |
data_tts/gcloud_tts_sample_1217.wav filter=lfs diff=lfs merge=lfs -text
|
| 957 |
+
data_tts/gcloud_tts_sample_1063.wav filter=lfs diff=lfs merge=lfs -text
|
| 958 |
+
data_tts/gcloud_tts_sample_106.wav filter=lfs diff=lfs merge=lfs -text
|
| 959 |
+
data_tts/gcloud_tts_sample_1061.wav filter=lfs diff=lfs merge=lfs -text
|
| 960 |
+
data_tts/gcloud_tts_sample_1068.wav filter=lfs diff=lfs merge=lfs -text
|
| 961 |
+
data_tts/gcloud_tts_sample_1069.wav filter=lfs diff=lfs merge=lfs -text
|
| 962 |
+
data_tts/gcloud_tts_sample_1070.wav filter=lfs diff=lfs merge=lfs -text
|
| 963 |
+
data_tts/gcloud_tts_sample_1066.wav filter=lfs diff=lfs merge=lfs -text
|
| 964 |
+
data_tts/gcloud_tts_sample_1071.wav filter=lfs diff=lfs merge=lfs -text
|
| 965 |
+
data_tts/gcloud_tts_sample_1064.wav filter=lfs diff=lfs merge=lfs -text
|
| 966 |
+
data_tts/gcloud_tts_sample_1056.wav filter=lfs diff=lfs merge=lfs -text
|
| 967 |
+
data_tts/gcloud_tts_sample_1073.wav filter=lfs diff=lfs merge=lfs -text
|
| 968 |
+
data_tts/gcloud_tts_sample_1075.wav filter=lfs diff=lfs merge=lfs -text
|
| 969 |
+
data_tts/gcloud_tts_sample_1072.wav filter=lfs diff=lfs merge=lfs -text
|
| 970 |
+
data_tts/gcloud_tts_sample_1079.wav filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import sounddevice as sd
|
| 2 |
+
# import streamlit as st
|
| 3 |
+
# import os
|
| 4 |
+
# import re
|
| 5 |
+
# import numpy as np
|
| 6 |
+
# import wave
|
| 7 |
+
# import requests
|
| 8 |
+
# from datetime import datetime
|
| 9 |
+
|
| 10 |
+
# API_URL = "http://localhost:8000/transcribe"
|
| 11 |
+
|
| 12 |
+
# # Record audio
|
| 13 |
+
# def record_audio(duration=15, fs=16000):
|
| 14 |
+
# st.write("🔴 Recording... Speak Arabic now!")
|
| 15 |
+
# recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
|
| 16 |
+
# sd.wait()
|
| 17 |
+
# st.write("✅ Recording finished")
|
| 18 |
+
# return recording, fs
|
| 19 |
+
|
| 20 |
+
# # Save recording
|
| 21 |
+
# def save_wav(recording, fs, out_dir="recordings"):
|
| 22 |
+
# os.makedirs(out_dir, exist_ok=True)
|
| 23 |
+
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 24 |
+
# file_path = os.path.join(out_dir, f"recording_{timestamp}.wav")
|
| 25 |
+
|
| 26 |
+
# # Normalize
|
| 27 |
+
# max_val = np.max(np.abs(recording))
|
| 28 |
+
# if max_val > 0:
|
| 29 |
+
# recording = (recording / max_val * 32767).astype(np.int16)
|
| 30 |
+
|
| 31 |
+
# with wave.open(file_path, "wb") as wf:
|
| 32 |
+
# wf.setnchannels(1)
|
| 33 |
+
# wf.setsampwidth(2)
|
| 34 |
+
# wf.setframerate(fs)
|
| 35 |
+
# wf.writeframes(recording.tobytes())
|
| 36 |
+
|
| 37 |
+
# return file_path
|
| 38 |
+
|
| 39 |
+
# # Call API
|
| 40 |
+
# def transcribe_audio(file_path):
|
| 41 |
+
# with open(file_path, "rb") as f:
|
| 42 |
+
# files = {"file": (file_path, f, "audio/wav")}
|
| 43 |
+
# response = requests.post(API_URL, files=files)
|
| 44 |
+
|
| 45 |
+
# if response.status_code == 200:
|
| 46 |
+
# return response.json().get("transcription", "")
|
| 47 |
+
# else:
|
| 48 |
+
# st.error(f"❌ API Error {response.status_code}: {response.text}")
|
| 49 |
+
# return ""
|
| 50 |
+
|
| 51 |
+
# # Extract phone number
|
| 52 |
+
# def extract_phone_number(text):
|
| 53 |
+
# match = re.search(r"01[0-9]{9}", text)
|
| 54 |
+
# return match.group(0) if match else None
|
| 55 |
+
|
| 56 |
+
# # Extract national ID
|
| 57 |
+
# def extract_national_id(text):
|
| 58 |
+
# digits = re.findall(r"\d+", text)
|
| 59 |
+
# candidate = "".join(digits)
|
| 60 |
+
# if len(candidate) == 14:
|
| 61 |
+
# return candidate
|
| 62 |
+
# elif len(candidate) > 14:
|
| 63 |
+
# return candidate[:14]
|
| 64 |
+
# elif 7 <= len(candidate) < 14:
|
| 65 |
+
# return f"⚠️ Incomplete ID: {candidate} ({len(candidate)} digits)"
|
| 66 |
+
# else:
|
| 67 |
+
# return None
|
| 68 |
+
|
| 69 |
+
# # ---------------- UI ----------------
|
| 70 |
+
# st.title("📞 Phone & National ID Capture (with Name + Case Name)")
|
| 71 |
+
|
| 72 |
+
# # Session state
|
| 73 |
+
# if "phone_number" not in st.session_state:
|
| 74 |
+
# st.session_state.phone_number = None
|
| 75 |
+
# if "national_id" not in st.session_state:
|
| 76 |
+
# st.session_state.national_id = None
|
| 77 |
+
# if "name" not in st.session_state:
|
| 78 |
+
# st.session_state.name = ""
|
| 79 |
+
# if "case_name" not in st.session_state:
|
| 80 |
+
# st.session_state.case_name = ""
|
| 81 |
+
|
| 82 |
+
# # Step 1: Phone number
|
| 83 |
+
# st.subheader("Step 1: Provide your phone number")
|
| 84 |
+
# col1, col2 = st.columns(2)
|
| 85 |
+
|
| 86 |
+
# with col1:
|
| 87 |
+
# if st.button("🎙️ Record Phone Number"):
|
| 88 |
+
# rec, fs = record_audio()
|
| 89 |
+
# wav_path = save_wav(rec, fs)
|
| 90 |
+
# st.audio(wav_path)
|
| 91 |
+
# text = transcribe_audio(wav_path)
|
| 92 |
+
# st.write("📝 Transcription:", text)
|
| 93 |
+
# phone = extract_phone_number(text)
|
| 94 |
+
# if phone:
|
| 95 |
+
# st.session_state.phone_number = phone
|
| 96 |
+
# st.success(f"📱 Detected Phone Number: {phone}")
|
| 97 |
+
# else:
|
| 98 |
+
# st.error("❌ No valid phone number detected")
|
| 99 |
+
|
| 100 |
+
# with col2:
|
| 101 |
+
# phone_upload = st.file_uploader("Or upload phone number audio", type=["wav", "mp3", "m4a"])
|
| 102 |
+
# if phone_upload is not None:
|
| 103 |
+
# temp_path = os.path.join("recordings", f"upload_phone_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 104 |
+
# os.makedirs("recordings", exist_ok=True)
|
| 105 |
+
# with open(temp_path, "wb") as f:
|
| 106 |
+
# f.write(phone_upload.read())
|
| 107 |
+
# st.audio(temp_path)
|
| 108 |
+
# text = transcribe_audio(temp_path)
|
| 109 |
+
# st.write("📝 Transcription:", text)
|
| 110 |
+
# phone = extract_phone_number(text)
|
| 111 |
+
# if phone:
|
| 112 |
+
# st.session_state.phone_number = phone
|
| 113 |
+
# st.success(f"📱 Detected Phone Number: {phone}")
|
| 114 |
+
# else:
|
| 115 |
+
# st.error("❌ No valid phone number detected")
|
| 116 |
+
|
| 117 |
+
# # Step 2: National ID
|
| 118 |
+
# st.subheader("Step 2: Provide your national ID")
|
| 119 |
+
# col3, col4 = st.columns(2)
|
| 120 |
+
|
| 121 |
+
# with col3:
|
| 122 |
+
# if st.button("🎙️ Record National ID"):
|
| 123 |
+
# rec, fs = record_audio()
|
| 124 |
+
# wav_path = save_wav(rec, fs)
|
| 125 |
+
# st.audio(wav_path)
|
| 126 |
+
# text = transcribe_audio(wav_path)
|
| 127 |
+
# st.write("📝 Transcription:", text)
|
| 128 |
+
# nid = extract_national_id(text)
|
| 129 |
+
# if nid:
|
| 130 |
+
# st.session_state.national_id = nid
|
| 131 |
+
# st.success(f"🪪 Detected National ID: {nid}")
|
| 132 |
+
# else:
|
| 133 |
+
# st.error("❌ No valid national ID detected")
|
| 134 |
+
|
| 135 |
+
# with col4:
|
| 136 |
+
# nid_upload = st.file_uploader("Or upload national ID audio", type=["wav", "mp3", "m4a"])
|
| 137 |
+
# if nid_upload is not None:
|
| 138 |
+
# temp_path = os.path.join("recordings", f"upload_nid_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 139 |
+
# os.makedirs("recordings", exist_ok=True)
|
| 140 |
+
# with open(temp_path, "wb") as f:
|
| 141 |
+
# f.write(nid_upload.read())
|
| 142 |
+
# st.audio(temp_path)
|
| 143 |
+
# text = transcribe_audio(temp_path)
|
| 144 |
+
# st.write("📝 Transcription:", text)
|
| 145 |
+
# nid = extract_national_id(text)
|
| 146 |
+
# if nid:
|
| 147 |
+
# st.session_state.national_id = nid
|
| 148 |
+
# st.success(f"🪪 Detected National ID: {nid}")
|
| 149 |
+
# else:
|
| 150 |
+
# st.error("❌ No valid national ID detected")
|
| 151 |
+
|
| 152 |
+
# # Step 3: Manual fields
|
| 153 |
+
# st.subheader("Step 3: Provide additional info")
|
| 154 |
+
# st.session_state.name = st.text_input("👤 Enter your Name", st.session_state.name)
|
| 155 |
+
# st.session_state.case_name = st.text_input("📂 Enter Case Name", st.session_state.case_name)
|
| 156 |
+
|
| 157 |
+
# # Final summary
|
| 158 |
+
# st.subheader("📋 Summary")
|
| 159 |
+
# if st.session_state.phone_number:
|
| 160 |
+
# st.info(f"📱 Phone Number: {st.session_state.phone_number}")
|
| 161 |
+
# if st.session_state.national_id:
|
| 162 |
+
# st.info(f"🪪 National ID: {st.session_state.national_id}")
|
| 163 |
+
# if st.session_state.name:
|
| 164 |
+
# st.info(f"👤 Name: {st.session_state.name}")
|
| 165 |
+
# if st.session_state.case_name:
|
| 166 |
+
# st.info(f"📂 Case Name: {st.session_state.case_name}")
|
| 167 |
+
|
| 168 |
+
# if st.session_state.phone_number and st.session_state.national_id and st.session_state.name and st.session_state.case_name:
|
| 169 |
+
# st.success("✅ All details captured successfully!")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
import sounddevice as sd
|
| 173 |
+
import streamlit as st
|
| 174 |
+
import os
|
| 175 |
+
import re
|
| 176 |
+
import numpy as np
|
| 177 |
+
import wave
|
| 178 |
+
import requests
|
| 179 |
+
from datetime import datetime
|
| 180 |
+
|
| 181 |
+
API_URL = "http://localhost:8070/transcribe"
|
| 182 |
+
|
| 183 |
+
# Record audio
|
| 184 |
+
def record_audio(duration=15, fs=16000):
|
| 185 |
+
st.write("🔴 Recording... Speak Arabic now!")
|
| 186 |
+
# recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
|
| 187 |
+
recording = sd.rec(int(16000 * 10), samplerate=16000, channels=1, dtype='int16')
|
| 188 |
+
sd.wait()
|
| 189 |
+
st.write("✅ Recording finished")
|
| 190 |
+
return recording, fs
|
| 191 |
+
|
| 192 |
+
# Save recording
|
| 193 |
+
# def save_wav(recording, fs, out_dir="recordings", prefix="recording"):
|
| 194 |
+
# os.makedirs(out_dir, exist_ok=True)
|
| 195 |
+
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 196 |
+
# file_path = os.path.join(out_dir, f"{prefix}_{timestamp}.wav")
|
| 197 |
+
|
| 198 |
+
# # Normalize
|
| 199 |
+
# max_val = np.max(np.abs(recording))
|
| 200 |
+
# if max_val > 0:
|
| 201 |
+
# recording = (recording / max_val * 32767).astype(np.int16)
|
| 202 |
+
|
| 203 |
+
# with wave.open(file_path, "wb") as wf:
|
| 204 |
+
# wf.setnchannels(1)
|
| 205 |
+
# wf.setsampwidth(2)
|
| 206 |
+
# wf.setframerate(fs)
|
| 207 |
+
# wf.writeframes(recording.tobytes())
|
| 208 |
+
|
| 209 |
+
# return file_path
|
| 210 |
+
import scipy.io.wavfile as wav
|
| 211 |
+
|
| 212 |
+
# def save_wav(recording, fs, out_dir="recordings", prefix="recording"):
|
| 213 |
+
# os.makedirs(out_dir, exist_ok=True)
|
| 214 |
+
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 215 |
+
# file_path = os.path.join(out_dir, f"{prefix}_{timestamp}.wav")
|
| 216 |
+
|
| 217 |
+
# # Save directly using scipy.io.wavfile
|
| 218 |
+
# wav.write(file_path, fs, recording)
|
| 219 |
+
|
| 220 |
+
# return file_path
|
| 221 |
+
# Call API
|
| 222 |
+
def transcribe_audio(file_path):
|
| 223 |
+
with open(file_path, "rb") as f:
|
| 224 |
+
files = {"file": (file_path, f, "audio/wav")}
|
| 225 |
+
response = requests.post(API_URL, files=files)
|
| 226 |
+
|
| 227 |
+
if response.status_code == 200:
|
| 228 |
+
return response.json().get("transcription", "")
|
| 229 |
+
else:
|
| 230 |
+
st.error(f"❌ API Error {response.status_code}: {response.text}")
|
| 231 |
+
return ""
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def save_wav(recording, fs, out_dir="recordings", prefix="recording"):
|
| 235 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 236 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 237 |
+
file_path = os.path.join(out_dir, f"{prefix}_{timestamp}.wav")
|
| 238 |
+
|
| 239 |
+
# Flatten to 1D if stereo-like shape
|
| 240 |
+
if recording.ndim > 1:
|
| 241 |
+
recording = recording[:, 0]
|
| 242 |
+
|
| 243 |
+
wav.write(file_path, fs, recording.astype(np.int16))
|
| 244 |
+
|
| 245 |
+
return file_path
|
| 246 |
+
|
| 247 |
+
# Extract phone number
|
| 248 |
+
def extract_phone_number(text):
|
| 249 |
+
digits = re.findall(r"\d+", text)
|
| 250 |
+
candidate = "".join(digits)
|
| 251 |
+
return candidate if candidate.startswith("01") and len(candidate) == 11 else None
|
| 252 |
+
|
| 253 |
+
# Extract national ID
|
| 254 |
+
def extract_national_id(text):
|
| 255 |
+
digits = re.findall(r"\d+", text)
|
| 256 |
+
candidate = "".join(digits)
|
| 257 |
+
if len(candidate) == 14:
|
| 258 |
+
return candidate
|
| 259 |
+
elif len(candidate) > 14:
|
| 260 |
+
return candidate[:14]
|
| 261 |
+
elif 7 <= len(candidate) < 14:
|
| 262 |
+
return f"⚠️ Incomplete ID: {candidate} ({len(candidate)} digits)"
|
| 263 |
+
else:
|
| 264 |
+
return None
|
| 265 |
+
|
| 266 |
+
# ---------------- UI ----------------
|
| 267 |
+
st.title("📞 Phone, National ID, Name & Case Name Capture")
|
| 268 |
+
|
| 269 |
+
# Session state
|
| 270 |
+
for key in ["phone_number", "national_id", "name", "case_name"]:
|
| 271 |
+
if key not in st.session_state:
|
| 272 |
+
st.session_state[key] = None
|
| 273 |
+
|
| 274 |
+
# Step 1: Phone number
|
| 275 |
+
st.subheader("Step 1: Provide your phone number")
|
| 276 |
+
col1, col2 = st.columns(2)
|
| 277 |
+
|
| 278 |
+
with col1:
|
| 279 |
+
if st.button("🎙️ Record Phone Number"):
|
| 280 |
+
rec, fs = record_audio()
|
| 281 |
+
wav_path = save_wav(rec, fs, prefix="phone")
|
| 282 |
+
st.audio(wav_path)
|
| 283 |
+
text = transcribe_audio(wav_path)
|
| 284 |
+
st.write("📝 Transcription:", text)
|
| 285 |
+
phone = extract_phone_number(text)
|
| 286 |
+
if phone:
|
| 287 |
+
st.session_state.phone_number = phone
|
| 288 |
+
st.success(f"📱 Detected Phone Number: {phone}")
|
| 289 |
+
else:
|
| 290 |
+
st.error("❌ No valid phone number detected")
|
| 291 |
+
|
| 292 |
+
with col2:
|
| 293 |
+
phone_upload = st.file_uploader("Or upload phone number audio", type=["wav", "mp3", "m4a"])
|
| 294 |
+
if phone_upload is not None:
|
| 295 |
+
temp_path = os.path.join("recordings", f"upload_phone_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 296 |
+
os.makedirs("recordings", exist_ok=True)
|
| 297 |
+
with open(temp_path, "wb") as f:
|
| 298 |
+
f.write(phone_upload.read())
|
| 299 |
+
st.audio(temp_path)
|
| 300 |
+
text = transcribe_audio(temp_path)
|
| 301 |
+
st.write("📝 Transcription:", text)
|
| 302 |
+
phone = extract_phone_number(text)
|
| 303 |
+
if phone:
|
| 304 |
+
st.session_state.phone_number = phone
|
| 305 |
+
st.success(f"📱 Detected Phone Number: {phone}")
|
| 306 |
+
else:
|
| 307 |
+
st.error("❌ No valid phone number detected")
|
| 308 |
+
|
| 309 |
+
# Step 2: National ID
|
| 310 |
+
st.subheader("Step 2: Provide your national ID")
|
| 311 |
+
col3, col4 = st.columns(2)
|
| 312 |
+
|
| 313 |
+
with col3:
|
| 314 |
+
if st.button("🎙️ Record National ID"):
|
| 315 |
+
rec, fs = record_audio()
|
| 316 |
+
wav_path = save_wav(rec, fs, prefix="nid")
|
| 317 |
+
st.audio(wav_path)
|
| 318 |
+
text = transcribe_audio(wav_path)
|
| 319 |
+
st.write("📝 Transcription:", text)
|
| 320 |
+
nid = extract_national_id(text)
|
| 321 |
+
if nid:
|
| 322 |
+
st.session_state.national_id = nid
|
| 323 |
+
st.success(f"🪪 Detected National ID: {nid}")
|
| 324 |
+
else:
|
| 325 |
+
st.error("❌ No valid national ID detected")
|
| 326 |
+
|
| 327 |
+
with col4:
|
| 328 |
+
nid_upload = st.file_uploader("Or upload national ID audio", type=["wav", "mp3", "m4a"])
|
| 329 |
+
if nid_upload is not None:
|
| 330 |
+
temp_path = os.path.join("recordings", f"upload_nid_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 331 |
+
os.makedirs("recordings", exist_ok=True)
|
| 332 |
+
with open(temp_path, "wb") as f:
|
| 333 |
+
f.write(nid_upload.read())
|
| 334 |
+
st.audio(temp_path)
|
| 335 |
+
text = transcribe_audio(temp_path)
|
| 336 |
+
st.write("📝 Transcription:", text)
|
| 337 |
+
nid = extract_national_id(text)
|
| 338 |
+
if nid:
|
| 339 |
+
st.session_state.national_id = nid
|
| 340 |
+
st.success(f"🪪 Detected National ID: {nid}")
|
| 341 |
+
else:
|
| 342 |
+
st.error("❌ No valid national ID detected")
|
| 343 |
+
|
| 344 |
+
# Step 3: Name (audio input)
|
| 345 |
+
st.subheader("Step 3: Provide your Name")
|
| 346 |
+
col5, col6 = st.columns(2)
|
| 347 |
+
|
| 348 |
+
with col5:
|
| 349 |
+
if st.button("🎙️ Record Name"):
|
| 350 |
+
rec, fs = record_audio()
|
| 351 |
+
wav_path = save_wav(rec, fs, prefix="name")
|
| 352 |
+
st.audio(wav_path)
|
| 353 |
+
text = transcribe_audio(wav_path)
|
| 354 |
+
st.write("📝 Transcription:", text)
|
| 355 |
+
if text.strip():
|
| 356 |
+
st.session_state.name = text.strip()
|
| 357 |
+
st.success(f"👤 Name: {text.strip()}")
|
| 358 |
+
|
| 359 |
+
with col6:
|
| 360 |
+
name_upload = st.file_uploader("Or upload name audio", type=["wav", "mp3", "m4a"])
|
| 361 |
+
if name_upload is not None:
|
| 362 |
+
temp_path = os.path.join("recordings", f"upload_name_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 363 |
+
os.makedirs("recordings", exist_ok=True)
|
| 364 |
+
with open(temp_path, "wb") as f:
|
| 365 |
+
f.write(name_upload.read())
|
| 366 |
+
st.audio(temp_path)
|
| 367 |
+
text = transcribe_audio(temp_path)
|
| 368 |
+
st.write("📝 Transcription:", text)
|
| 369 |
+
if text.strip():
|
| 370 |
+
st.session_state.name = text.strip()
|
| 371 |
+
st.success(f"👤 Name: {text.strip()}")
|
| 372 |
+
|
| 373 |
+
# Step 4: Case Name (audio input)
|
| 374 |
+
st.subheader("Step 4: Provide Case Name")
|
| 375 |
+
col7, col8 = st.columns(2)
|
| 376 |
+
|
| 377 |
+
with col7:
|
| 378 |
+
if st.button("🎙️ Record Case Name"):
|
| 379 |
+
rec, fs = record_audio()
|
| 380 |
+
wav_path = save_wav(rec, fs, prefix="case_name")
|
| 381 |
+
st.audio(wav_path)
|
| 382 |
+
text = transcribe_audio(wav_path)
|
| 383 |
+
st.write("📝 Transcription:", text)
|
| 384 |
+
if text.strip():
|
| 385 |
+
st.session_state.case_name = text.strip()
|
| 386 |
+
st.success(f"📂 Case Name: {text.strip()}")
|
| 387 |
+
|
| 388 |
+
with col8:
|
| 389 |
+
case_upload = st.file_uploader("Or upload case name audio", type=["wav", "mp3", "m4a"])
|
| 390 |
+
if case_upload is not None:
|
| 391 |
+
temp_path = os.path.join("recordings", f"upload_case_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav")
|
| 392 |
+
os.makedirs("recordings", exist_ok=True)
|
| 393 |
+
with open(temp_path, "wb") as f:
|
| 394 |
+
f.write(case_upload.read())
|
| 395 |
+
st.audio(temp_path)
|
| 396 |
+
text = transcribe_audio(temp_path)
|
| 397 |
+
st.write("📝 Transcription:", text)
|
| 398 |
+
if text.strip():
|
| 399 |
+
st.session_state.case_name = text.strip()
|
| 400 |
+
st.success(f"📂 Case Name: {text.strip()}")
|
| 401 |
+
|
| 402 |
+
# Final summary
|
| 403 |
+
st.subheader("📋 Summary")
|
| 404 |
+
if st.session_state.phone_number:
|
| 405 |
+
st.info(f"📱 Phone Number: {st.session_state.phone_number}")
|
| 406 |
+
if st.session_state.national_id:
|
| 407 |
+
st.info(f"🪪 National ID: {st.session_state.national_id}")
|
| 408 |
+
if st.session_state.name:
|
| 409 |
+
st.info(f"👤 Name: {st.session_state.name}")
|
| 410 |
+
if st.session_state.case_name:
|
| 411 |
+
st.info(f"📂 Case Name: {st.session_state.case_name}")
|
| 412 |
+
|
| 413 |
+
if st.session_state.phone_number and st.session_state.national_id and st.session_state.name and st.session_state.case_name:
|
| 414 |
+
st.success("✅ All details captured successfully!")
|
data_tts/gcloud_tts_sample_1056.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9333b44bb49675dff79edb354241435ed24507dfc635e53092388905416b7e4c
|
| 3 |
+
size 169024
|
data_tts/gcloud_tts_sample_106.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:43445c70dd5c0d5044e572a74bc69dffc339945b99af9efe5031276a747ef909
|
| 3 |
+
size 130108
|
data_tts/gcloud_tts_sample_1061.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3524af71bf64a5b8a59f4de4bdff13420f6194b6b453b14e7ee49789dfbb95c2
|
| 3 |
+
size 147324
|
data_tts/gcloud_tts_sample_1063.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:052cff5f5a08273ac351ffadc3da7c2d6e1f409ce70d1a1a394206b8e1fae99a
|
| 3 |
+
size 161550
|
data_tts/gcloud_tts_sample_1064.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82cc4726b248be1cbd47af2df3cab02d0d8f2dca917affda2ac2d50f49f6827d
|
| 3 |
+
size 130260
|
data_tts/gcloud_tts_sample_1066.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5526c0adabc6a79521fe45f4ad2add8311fd2808ba1f1ea119ec8cfc7c8fbed6
|
| 3 |
+
size 168918
|
data_tts/gcloud_tts_sample_1068.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d43068a068ddf96a420413ee1ec2ad26dfacc337a9da1f80f3b8bbaedd0c00cf
|
| 3 |
+
size 139066
|
data_tts/gcloud_tts_sample_1069.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8028cc6732c60b03851aa21d07d4c13022e27ab88541eca9019cf6209f47e564
|
| 3 |
+
size 119588
|
data_tts/gcloud_tts_sample_1070.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9017d2c8c9737a2dc4819a10019a81b588bb59296f38e42821628fb97e146d95
|
| 3 |
+
size 153662
|
data_tts/gcloud_tts_sample_1071.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:10f2eccbad15023901450e5bb7a4ca33a067376f08748110ee66485d513103c0
|
| 3 |
+
size 135812
|
data_tts/gcloud_tts_sample_1072.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:135a90200801bc5ee7fcd24a13d5bc649c503193a4fd8937726d0f19e8ffe57d
|
| 3 |
+
size 169292
|
data_tts/gcloud_tts_sample_1073.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2ea22ae2e484ee740bec3e6a7a0e31d41c5518e6a0ad0b5f462f42874c5d053a
|
| 3 |
+
size 152684
|
data_tts/gcloud_tts_sample_1075.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:234d47f5344f3543812e8322a6fcc485726c7108084c8cf84988dbae6ea3b65e
|
| 3 |
+
size 153386
|
data_tts/gcloud_tts_sample_1079.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4079db5596b969843598eeeb223510241812614f92464fd91913d1289dca7336
|
| 3 |
+
size 178802
|
data_tts/gcloud_tts_sample_1184.wav
ADDED
|
Binary file (48.7 kB). View file
|
|
|
data_tts/gcloud_tts_sample_1185.wav
ADDED
|
Binary file (75.2 kB). View file
|
|
|
data_tts/gcloud_tts_sample_1186.wav
ADDED
|
Binary file (75.1 kB). View file
|
|
|
data_tts/gcloud_tts_sample_1187.wav
ADDED
|
Binary file (64.5 kB). View file
|
|
|
data_tts/gcloud_tts_sample_1188.wav
ADDED
|
Binary file (81.7 kB). View file
|
|
|