Spaces:
Paused
Paused
HARI PREETHAM commited on
Commit ·
44e7f68
1
Parent(s): e7b11c5
\Enable Azure Whisper model support + prompt hints"
Browse files
app.py
CHANGED
|
@@ -129,9 +129,10 @@ async def transcribe_audio(
|
|
| 129 |
@app.post("/api/transcribe/azure", response_model=TranscriptionResponse)
|
| 130 |
async def transcribe_azure(
|
| 131 |
file: UploadFile = File(...),
|
| 132 |
-
language: Optional[str] = Form(None)
|
|
|
|
| 133 |
):
|
| 134 |
-
"""Transcribes audio using Azure AI Speech (Whisper)"""
|
| 135 |
key = os.getenv("AZURE_SPEECH_KEY")
|
| 136 |
region = os.getenv("AZURE_SPEECH_REGION")
|
| 137 |
|
|
@@ -153,16 +154,29 @@ async def transcribe_azure(
|
|
| 153 |
|
| 154 |
# Configure Azure Speech
|
| 155 |
speech_config = speechsdk.SpeechConfig(subscription=key, region=region)
|
| 156 |
-
|
| 157 |
-
#
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
if language:
|
| 160 |
speech_config.speech_recognition_language = language
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
audio_config = speechsdk.audio.AudioConfig(filename=wav_path)
|
| 163 |
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
|
| 164 |
|
| 165 |
-
logger.info(f"Azure Transcribing {file.filename} | Lang: {language}")
|
| 166 |
|
| 167 |
# Perform recognition
|
| 168 |
result = speech_recognizer.recognize_once_async().get()
|
|
|
|
| 129 |
@app.post("/api/transcribe/azure", response_model=TranscriptionResponse)
|
| 130 |
async def transcribe_azure(
|
| 131 |
file: UploadFile = File(...),
|
| 132 |
+
language: Optional[str] = Form(None),
|
| 133 |
+
initial_prompt: Optional[str] = Form(None)
|
| 134 |
):
|
| 135 |
+
"""Transcribes audio using Azure AI Speech (specifically Whisper model)"""
|
| 136 |
key = os.getenv("AZURE_SPEECH_KEY")
|
| 137 |
region = os.getenv("AZURE_SPEECH_REGION")
|
| 138 |
|
|
|
|
| 154 |
|
| 155 |
# Configure Azure Speech
|
| 156 |
speech_config = speechsdk.SpeechConfig(subscription=key, region=region)
|
| 157 |
+
|
| 158 |
+
# MANDATORY: Set model to whisper for using the Whisper engine on Azure Speech Service
|
| 159 |
+
speech_config.set_service_property(
|
| 160 |
+
name='speech.model',
|
| 161 |
+
value='whisper',
|
| 162 |
+
strategy=speechsdk.ServicePropertyChannel.UriQueryParameter
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
if language:
|
| 166 |
speech_config.speech_recognition_language = language
|
| 167 |
+
|
| 168 |
+
if initial_prompt:
|
| 169 |
+
# Pass the Whisper prompt to help with specific vocabulary or language hints
|
| 170 |
+
speech_config.set_service_property(
|
| 171 |
+
name='whisper.prompt',
|
| 172 |
+
value=initial_prompt,
|
| 173 |
+
strategy=speechsdk.ServicePropertyChannel.UriQueryParameter
|
| 174 |
+
)
|
| 175 |
|
| 176 |
audio_config = speechsdk.audio.AudioConfig(filename=wav_path)
|
| 177 |
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
|
| 178 |
|
| 179 |
+
logger.info(f"Azure (Whisper) Transcribing {file.filename} | Lang: {language}")
|
| 180 |
|
| 181 |
# Perform recognition
|
| 182 |
result = speech_recognizer.recognize_once_async().get()
|