Skip to content

Commit 97f102d

Browse files
committed
🐛(backend) handle empty transcription files gracefully
Add handling for when users forget to activate microphones resulting in empty transcripts. User message not yet internationalized, planned for next version. Add friendly instructions to give them hint about the situation.
1 parent e816475 commit 97f102d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/summary/summary/core/celery_worker.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ def init_sentry(**_kwargs):
3636
sentry_sdk.init(dsn=settings.sentry_dsn, enable_tracing=True)
3737

3838

39+
DEFAULT_EMPTY_TRANSCRIPTION = """
40+
**Aucun contenu audio n’a été détecté dans votre transcription.**
41+
42+
43+
*Si vous pensez qu’il s’agit d’une erreur, n’hésitez pas à contacter
44+
notre support technique : visio@numerique.gouv.fr*
45+
46+
.
47+
48+
.
49+
50+
.
51+
52+
Quelques points que nous vous conseillons de vérifier :
53+
- Un micro était-il activé ?
54+
- Étiez-vous suffisamment proche ?
55+
- Le micro est-il de bonne qualité ?
56+
- L’enregistrement dure-t-il plus de 30 secondes ?
57+
58+
"""
59+
60+
3961
def save_audio_stream(audio_stream, chunk_size=32 * 1024):
4062
"""Save an audio stream to a temporary OGG file."""
4163
with tempfile.NamedTemporaryFile(suffix=".ogg", delete=False) as tmp:
@@ -219,7 +241,11 @@ def process_audio_transcribe_summarize_v2(filename: str, email: str, sub: str):
219241
os.remove(temp_file_path)
220242
logger.debug("Temporary file removed: %s", temp_file_path)
221243

222-
formatted_transcription = format_segments(transcription)
244+
formatted_transcription = (
245+
DEFAULT_EMPTY_TRANSCRIPTION
246+
if not transcription.segment
247+
else format_segments(transcription)
248+
)
223249

224250
data = {
225251
"title": "Transcription",

0 commit comments

Comments
 (0)