Notes
Notes - notes.io |
import json
from deepgram import Deepgram
from pydub import AudioSegment
import re
import wave
import numpy as np
DEEPGRAM_API_KEY = 'f0ca2acc45aca377f846be8eb2221c01945d1f4e'
PATH_TO_FILE = "/home/admin1/Desktop/test_audio/word1.wav"
PROFANE_WORDS = ["fucking", "bastard"] # Replace this with your list of profane words
# Load the beep sound
beep_sound_path = "/home/admin1/Downloads/censor-beep-01.wav"
beep_sound = AudioSegment.from_wav(beep_sound_path)
with wave.open(beep_sound_path, 'rb') as wav_file:
# Get the frame rate (frames per second) of the beep sound
frame_rate = wav_file.getframerate()
print("frame_rate:", frame_rate)
def censor_profane_words(transcript):
censored_audio = AudioSegment.empty()
cursor = 0 # Track the cursor position in the audio
for profane_word in PROFANE_WORDS:
word_occurrences = [m.start() for m in re.finditer(re.escape(profane_word), transcript, re.IGNORECASE)]
print("word_occurrences", word_occurrences)
i = 0
for start_time in word_occurrences:
print("Start time:", start_time)
# Calculate the duration of the profane word in milliseconds
duration_ms = len(profane_word) * (1000 / frame_rate)
print("duration_ms:", duration_ms)
print("word_length:", len(profane_word))
# Add non-profane audio before the profane word
non_profane_audio = AudioSegment.from_wav(PATH_TO_FILE)[cursor:int(start_time * frame_rate / 1000)]
# print("cursor:",cursor)
# print(int(start_time * frame_rate / 1000))
# print("non_profane_audio:", non_profane_audio)
censored_audio += non_profane_audio
print("censored_audio1:", censored_audio)
# Add beep sound for the profane word duration
censored_audio += beep_sound
print("censored_audio12:",censored_audio)
# print("beep_sound:",beep_sound)
# Update the cursor position
cursor = int(start_time * frame_rate / 1000) + int(2*duration_ms)
print("z:",int(start_time * frame_rate / 1000))
print("z1:",int(2*duration_ms))
print("cursor:", cursor)
i=i+1
# Add any remaining non-profane audio after the last profane word
remaining_audio = AudioSegment.from_wav(PATH_TO_FILE)[cursor:]
print("remaing_audio:", remaining_audio)
censored_audio += remaining_audio
print("censored_audio:", censored_audio)
return censored_audio
def main():
deepgram = Deepgram(DEEPGRAM_API_KEY)
with open(PATH_TO_FILE, 'rb') as audio_file:
source = {'buffer': audio_file, 'mimetype': 'audio/wav'}
response = deepgram.transcription.sync_prerecorded(source, {'punctuate': True})
if 'results' in response and 'channels' in response['results']:
transcript = response['results']['channels'][0]['alternatives'][0]['transcript']
censored_audio = censor_profane_words(transcript)
censored_audio.export("/home/admin1/Downloads/censored_output.wav", format="wav")
print("Censored audio saved successfully.")
else:
print("Transcription not available in the response.")
if __name__ == "__main__":
main()
|
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team