browser audio detection phase 3
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
"""Public, advisory configuration for the optional browser processing beta."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from django.templatetags.static import static
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@@ -11,7 +14,10 @@ SPEECH_LABEL_TERMS = (
|
||||
"speech", "conversation", "narration", "monologue", "babbling", "whisper",
|
||||
"speaking", "speech synthesizer",
|
||||
)
|
||||
GATE_RESULTS = {"whitelist_match", "no_match", "unavailable", "error"}
|
||||
GATE_RESULTS = {"whitelist_match", "speech_only", "no_match", "unavailable", "error"}
|
||||
RELEVANCE_THRESHOLD = 0.5
|
||||
SPEECH_THRESHOLD = 0.5
|
||||
MODEL_VERSION = "google-yamnet-1"
|
||||
|
||||
|
||||
def browser_config():
|
||||
@@ -31,15 +37,23 @@ def browser_policy():
|
||||
"whitelist": [],
|
||||
"privacy_sensitive_speech": [],
|
||||
"thresholds": {},
|
||||
"model_version": MODEL_VERSION,
|
||||
"model_url": "",
|
||||
"class_map_url": "",
|
||||
}
|
||||
if not enabled:
|
||||
return policy
|
||||
rules = ClassificationRule.objects.filter(enabled=True).order_by("value")
|
||||
policy["whitelist"] = list(rules.filter(rule_type=ClassificationRule.RuleType.WHITELIST).values_list("value", flat=True))
|
||||
policy["privacy_sensitive_speech"] = [
|
||||
value for value in rules.filter(rule_type=ClassificationRule.RuleType.BLACKLIST).values_list("value", flat=True)
|
||||
if any(term in value.lower() for term in SPEECH_LABEL_TERMS)
|
||||
]
|
||||
class_map_path = Path(__file__).parent / "static/browser-yamnet/yamnet_class_map.json"
|
||||
class_names = json.loads(class_map_path.read_text(encoding="utf-8"))
|
||||
speech_classes = {name for name in class_names if any(term in name.lower() for term in SPEECH_LABEL_TERMS)}
|
||||
speech_classes.update(value for value in rules.filter(rule_type=ClassificationRule.RuleType.BLACKLIST).values_list("value", flat=True)
|
||||
if any(term in value.lower() for term in SPEECH_LABEL_TERMS))
|
||||
policy["privacy_sensitive_speech"] = sorted(speech_classes)
|
||||
policy["thresholds"] = {"relevance": RELEVANCE_THRESHOLD, "speech": SPEECH_THRESHOLD}
|
||||
policy["model_url"] = static("browser-yamnet/model.json")
|
||||
policy["class_map_url"] = static("browser-yamnet/yamnet_class_map.json")
|
||||
return policy
|
||||
|
||||
|
||||
@@ -64,4 +78,7 @@ def advisory_browser_metadata(post_data):
|
||||
gate_result = submitted.get("browser_gate_result")
|
||||
if isinstance(gate_result, str) and gate_result in GATE_RESULTS:
|
||||
metadata["browser_gate_result"] = gate_result
|
||||
speech = submitted.get("browser_speech_detected")
|
||||
if type(speech) is bool:
|
||||
metadata["browser_speech_detected"] = speech
|
||||
return metadata
|
||||
|
||||
Reference in New Issue
Block a user