あなたの質問は特定のプログラミング関連の問題を求めているわけではありませんが、似たようなことに取り組んでいるので、答えようとします。
プログラムを使用して、録音の特定の部分を自動的にスクランブルできますか?
確かにできます。それは、どれだけ複雑にしたいかによって異なります。
複雑な方法がありますが、非常に基本的な概念の観点から、録音されたオーディオ ファイルを取得し、次の段階で処理する必要があります。
音声ファイル内の単語を分割 : これには、単語間の無音認識が必要です。
- 各単語を音声認識システムに通す
- スクランブルする方法を思いつく。を沈黙させますか 、
、または
jumble
で埋めます。white noise
encode
- 選択した方法に基づいて
scramble
一致する単語がある場合は、認識した単語を目的の単語と比較しますscramble
- ( ) のすべての単語を適切な順序で組み合わせ
concatenate
て保存します。
上記(4)以外の基本的なプロトタイプをまとめました。このプログラムはpydubを多用しており、オーディオを簡単に操作できます。そのチュートリアルはこちらにあります。
プログラムは基本的に、
1)このサイトからオープンソースの事前に録音された wav ファイルをダウンロードし0
て10
、 を使用してそれらを連結しましたpydub
。
プログラムは、指定されたオーディオ ファイルを 1 秒単位でスライスします。大胆さを使用して各単語を区切り、1 秒のウィンドウに収まるようにしました。実生活では、そうではありません。
2) 次に、Google 音声認識エンジンを介して単語を渡し、認識された単語を表示します。ご覧のとおり、単語six
は正しく認識されていません。speech recognition engine
この目的のためには、堅牢なものが必要です。
3) プログラムは 3 つの異なるscramble
方法を提供します。
- a) 単語を逆にする
- b) 単語を同等のものに置き換える
white noise
- c)単語を次のように置き換えます
silence
4) 次に、3 つの単語を選択9
し、4
上記2
のscramble
方法を適用して、対応する単語ファイルを置き換えます。
5) 次に、すべての単語とスクランブルされた単語を適切な順序で連結し、出力ファイルを作成します。
注: スクランブルする単語と認識された単語の比較を追加する時間がありませんでした。
ご不明な点がございましたら、お知らせください。
****デモコード:****
""" Declarations """
import speech_recognition as sr
from pydub import AudioSegment
from pydub.silence import split_on_silence
from pydub.generators import WhiteNoise
from pydub.playback import play
""" Function for Speech Recognition """
def processAudio(WAV_FILE):
r = sr.Recognizer()
with sr.WavFile(WAV_FILE) as source:
audio = r.record(source) # read the entire WAV file
# recognize speech using Google Speech Recognition
try:
print("recognizedWord=" + r.recognize_google(audio))
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results from GSR; {0}".format(e))
""" Function to scramble word based upon choice """
def scramble_audio(aWord, option):
scramble_file = export_path + "slice" + str(aWord) +".wav"
scramble_audioseg = AudioSegment.from_wav(scramble_file)
aWord_length = scramble_audioseg.__len__() #Get length of word segment to scramble
if option == "reverse": #Reverse word to scramble
scrambled_word = scramble_audioseg.reverse()
elif option == "whiteNoise": #Replace word to scramble with white noise
wn = WhiteNoise() #Instantiate White Noise Object
aWord_length = scramble_audioseg.__len__() #Get length of word segment
scrambled_word = wn.to_audio_segment(duration=aWord_length) #Create audio_segment
elif option == "silence": #Replace word to scramble with silence
scrambled_word = AudioSegment.silent(duration=aWord_length)
print ("Scrambling and Exporting %s" % scramble_file)
scrambled_word.export(scramble_file, format="wav") #Export merged audio file
if __name__ == "__main__":
export_path = ".//splitAudio//"
in_audio_file = "0-10.wav"
out_audio_file = export_path + "scrambledAudio.wav"
#Read main audio file to be processed. Assuming in the same folder as this script
sound = AudioSegment.from_wav(in_audio_file)
sec2_splice = 1 #Splice threshold in sec
audio_length = len(sound) # Total Audio Length In millisec
q, r = divmod(audio_length, sec2_splice) #Get quotient and remainder
#Get total segments and rounds to next greater integer
total_segments= (q + int(bool(r)) ) / 1000 #Converting to sec
#Iterate through slices every one second and export
print ("")
n=0
while n <= total_segments:
print ("Making slice from %d to %d (sec)" % (n , sec2_splice ))
temp_object = sound[ (n * 1000) : (sec2_splice * 1000)] #Slicing is done in millisec
myaudio_file = export_path + "slice" + str(n) +".wav"
temp_object.export(myaudio_file , format="wav")
print ("Trying to recognize %d " %n)
processAudio(myaudio_file)
n = sec2_splice
sec2_splice += 1
#Scramble desired audio slice
print ("")
scramble_word = 9
scramble_audio(scramble_word, "reverse" )
scramble_word = 4
scramble_audio(scramble_word, "whiteNoise" )
scramble_word = 2
scramble_audio(scramble_word, "silence" )
#Combine modified audio
final_audio = AudioSegment.empty() #Create empty AudioSegment
print ("")
i = 0
while i <= total_segments:
temp_audio_file = export_path + "slice" + str(i) +".wav"
temp_audio_seg = AudioSegment.from_wav(temp_audio_file)
print ("Combining %s" % temp_audio_file )
final_audio = final_audio.append(temp_audio_seg, crossfade=0)
i += 1
print ("Exporting final audio %s" % out_audio_file )
final_audio.export(out_audio_file , format="wav")
出力:
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Making slice from 0 to 1 (sec)
Trying to recognize 0
recognizedWord=0
Making slice from 1 to 2 (sec)
Trying to recognize 1
recognizedWord=1
Making slice from 2 to 3 (sec)
Trying to recognize 2
Could not understand audio
Making slice from 3 to 4 (sec)
Trying to recognize 3
recognizedWord=3
Making slice from 4 to 5 (sec)
Trying to recognize 4
recognizedWord=4
Making slice from 5 to 6 (sec)
Trying to recognize 5
recognizedWord=5
Making slice from 6 to 7 (sec)
Trying to recognize 6
recognizedWord=sex
Making slice from 7 to 8 (sec)
Trying to recognize 7
recognizedWord=7
Making slice from 8 to 9 (sec)
Trying to recognize 8
recognizedWord=8
Making slice from 9 to 10 (sec)
Trying to recognize 9
recognizedWord=9
Making slice from 10 to 11 (sec)
Trying to recognize 10
recognizedWord=10
Scrambling and Exporting .//splitAudio//slice9.wav
Scrambling and Exporting .//splitAudio//slice4.wav
Scrambling and Exporting .//splitAudio//slice2.wav
Combining .//splitAudio//slice0.wav
Combining .//splitAudio//slice1.wav
Combining .//splitAudio//slice2.wav
Combining .//splitAudio//slice3.wav
Combining .//splitAudio//slice4.wav
Combining .//splitAudio//slice5.wav
Combining .//splitAudio//slice6.wav
Combining .//splitAudio//slice7.wav
Combining .//splitAudio//slice8.wav
Combining .//splitAudio//slice9.wav
Combining .//splitAudio//slice10.wav
Exporting final audio .//splitAudio//scrambledAudio.wav
>>>