forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealtime.py
More file actions
27 lines (20 loc) · 906 Bytes
/
Copy pathrealtime.py
File metadata and controls
27 lines (20 loc) · 906 Bytes
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
import re
from fastapi import APIRouter
from models import *
router = APIRouter()
# *******************************************************
# ************ On Transcript Received Plugin ************
# *******************************************************
@router.post('/cursing-checker', tags=['basic', 'realtime'], response_model=EndpointResponse)
def cursing_checker(data: RealtimePluginRequest):
"""
This plugin checks if the transcript contains any curse words.
Without understanding the whole conversation. Just the new segments obtained.
"""
curse_words = ['shit', 'fuck', 'bitch', 'bastard']
transcript = TranscriptSegment.segments_as_string(data.segments)
text_lower = transcript.lower()
pattern = r'\b(?:' + '|'.join(map(re.escape, curse_words)) + r')\b'
if bool(re.search(pattern, text_lower)):
return {'message': 'Do not curse'}
return {}