Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Detecting Profanities in Responses

This feature requires a Premium Subscription. There is no additional per request cost to use it.

Set include_profanity_filter=1 on a request and Speechace checks the recognized text for profanity and marks the text spans of where it is. Use it to keep your app from showing a learner's profanity back to them, or to flag a response for review.

The feature only reports. It does not change anything else in the response, and it does not return a masked copy of the text. Your application decides whether to mask, hide, or reveal the flagged words.

How it works

  • Detect and flag. The response tells you whether profanity was found, how many profane words there are, and exactly where they sit in the text.

  • No impact on scoring or structure. Every score and every existing field is the same as in a request made without the flag. The flag only adds information.

  • You control redaction. The recognized text comes back unchanged. Your application applies whatever redaction it wants.

The flag is optional and off by default. When it is not set, the response is unchanged.

What the flag adds

With include_profanity_filter=1, the response gains a profanity object next to the recognized text:

Field
Type
Description

found

Boolean

true if any profanity was detected.

count

Integer

The number of profane words. This can be larger than the number of spans, because adjacent profane words are merged into one span.

redactions

Array

One {"span": [start, end]} entry per profane word or run of adjacent profane words. Offsets are zero-based character positions, both inclusive, into the original recognized text. Empty when nothing is found.

On the audio endpoints, each profane entry in word_score_list also gets "profanity": true. The word and all of its scores are unchanged.

A span marks the profane word. If the word is wrapped in extra characters, for example *word* or -word-, the span can include those characters too.

Endpoints

Endpoint
Recognized text (spans index into this)
profanity object
Word-level flag

speech_score.transcript

speech_score.profanity

speech_score.word_score_list[].profanity

task_score.transcript

task_score.profanity

speech_score.word_score_list[].profanity

answer (top level)

profanity (top level)

None (no word list)

A Score Task response carries both a task_score and a speech_score block. The per-word word_score_list lives under speech_score, so the word flags are set there. Both blocks share the same transcript.

Request Format

Send the request to the endpoint you already use, with one extra body parameter. The endpoint depends on the region of your subscription. For US West the base URL is https://api.speechace.co.

POST https://api.speechace.co/api/scoring/speech/v9/json

POST https://api.speechace.co/api/scoring/task/v9/json

POST https://api.speechace.co/api/scoring/writing/v9/json

key, dialect and the other query parameters stay as documented on each endpoint's page. The only addition is a form body field:

Parameter
Type
Description

include_profanity_filter

String

0 | 1 Optional: Set to 1 to detect profanity in the recognized text. Default 0.

Request Examples

Example
Request Parameters
When to use

A. Score Speech

user_audio_file=answer.wav include_profanity_filter="1"

Check a spoken answer. Spans index into the transcript and profane words are marked in word_score_list.

B. Score Writing

Query: task_type=essay-writing prompt="Describe a recent experience you had with online shopping." answer="Online shopping is convenient, but the return process is bullshit and the customer support was shit when my order arrived broken." include_profanity_filter="1"

Check written text. Spans index into answer.

Response Examples

The examples below were generated by the live API. Each endpoint is shown with profanity found and with a clean response.

The profane Score Speech response shows the two flagged entries in word_score_list. In the transcript, span [33, 36] is shit and span [64, 71] is bullshit. A clean response still includes the profanity object, with found: false, count: 0 and an empty redactions array.

Processing the response

Score Speech:

Score Writing returns the profanity object and the original text at the top level, and has no word list:

Notes

  • Language. Profanity detection is for English. Other languages are not covered yet.

  • What is flagged. The list targets profanity and common slurs. Mild words such as damn, hell or crap are not flagged.

  • Obfuscation. Common disguises such as **1* or *-*-*-* are detected. Stretched letters (*iiii*) and letters separated by spaces (* * * *) are not guaranteed to be caught, and a spaced-out word can raise count above the number of words.

  • Feedback text. Text that Speechace generates itself, such as score_explanation in a Score Task response, comes back with profanity already masked as ****. These masks are not included in redactions or count, which describe the recognized text only.

Last updated