Mask profanity words with bleep sound using SOX
Profanity is a type of language that includes dirty words and ideas. Swear words, obscene gestures, and naughty jokes are all considered…
Mask profanity words with bleep sound using SOX

freepik
Profanity is a type of language that includes dirty words and ideas. Swear words, obscene gestures, and naughty jokes are all considered profanity. Many creators don’t pronounce those words instead they add bleep-sound or mute particular words so that others can get the context of the word without pronouncing it
*If you call someone an a*hole, they’re probably doing something mean.
Let’s assume I have created a text-to-speech for the above text. It becomes a 3-second audio file and the interval of the word *a*hole is 1.2 sec to 1.8 sec (600ms).
Let’s add the bleep sound to the audio by doing the following steps:
- Trim the initial part from 0 to 1.2 sec
- Get initial audio of the word *a*hole so the user will understand what word it is trying to pronounce. Assume 20% of the word duration or 0.250 sec (whichever is minimum).
- For the rest of 80% word duration create a bleep sound.
- Trim the rest of the audio and concat all parts in order.
The Sox command will look like this:
const command = '''
sox
" |sox input.wav -p trim 0 1.2"
" |sox input.wav -p trim 1.2 0.120"
" |sox -n -r 48000 -p synth 0.48 sine 960 synth 0.48 sin fmod 100 vol 0.1"
" |sox input.wav -p trim 1.6 3.0"
output.wav
''';
Let's break this command in detail. Consider this as simple as
sox 1.wav 2.wav 3.wav 4.wav output.wav
Here 3.wav is the bleep sound and we are concatenating all the audio files in 1–2–3–4 order and storing them in output.wav.
Now replace 1.wav with
“ |sox input.wav -p trim 0 1.2”
Here we are trimming the input file which takes two arguments, 0 is the start time in seconds, and 1.2 is the duration in seconds.
The -p option is used to specify that the output should be sent to the standard output (stdout) instead of being written to a file.
Similarly, we have done for replacing 2.wav and 4.wav with the trim command.
3.wav is the actual bleep sound. Below mentioned commnad is used for creating the bleep sound
" |sox -n -r 48000 -p synth 0.48 sine 960 synth 0.48 sin fmod 100 vol 0.1"
-n: we not reading any input file.
-r 48000: Sets sample rate to 48,000 Hz.
synth 0.48 sine 960: Synthesis effect for generating sine wave of frequency 960 Hz for 0.48 seconds.
synth 0.48 sin fmod 100: We can play with the frequency modulation value to achieve smoother sound.
vol 0.1: Reduces the volume of the generated signal to 10% of its original amplitude.
And we are done!
Sometimes, the text-to-speech engine doesn’t give us actual word duration. If a special character is used in the word,!.?; , it can add an extra silence duration to the same word.
In the above example, we see the duration of a**hole was 600ms but a**hole, (mind the comma added here) will become 1.1 seconds.
To handle such edge cases, we can trim the silence region in the audio and get the actual duration of our word. With Sox, I was not able to get an easy solution for our problem, but ffmpeg solves this easily.
ffmpeg -i audio.wav -af "atrim=start=1.0125:end=1.6875, silencedetect=n=-50dB:d=0.1" -f null - 2>&1

silence-detect result using ffmpeg
In the above command, we have first trimmed the input audio for a specific word before doing silence detection.
-50 decibel sound for min0.1 second was the range selected for silence detection.
By using this information we can improve the bleep sound logic.
Append | grep silencedetect to ffmpeg command to to get filtered result and parse the data
Excited to hear your thoughts about this, hope this was a clear enough guide. Happy coding :)
메타데이터
- post_id
- b4f4acfdf69f
- slug
- mask-profanity-words-with-bleep-sound-using-sox-b4f4acfdf69f
- url
- https://medium.com/@rajatsangrame/mask-profanity-words-with-bleep-sound-using-sox-b4f4acfdf69f
- canonical_url
- https://medium.com/@rajatsangrame/mask-profanity-words-with-bleep-sound-using-sox-b4f4acfdf69f
- author_url
- https://medium.com/@rajatsangrame
- status
- ok
- fetched_at
- 2026-07-09 21:48:21