亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從現場應用程序中檢測特定聲音?

如何從現場應用程序中檢測特定聲音?

森林海 2022-09-06 16:50:45
有沒有辦法從應用程序(如chrome,mozilla)收集實時音頻,并在網站上播放特定聲音時執行一些代碼?
查看完整描述

1 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

如果您在使用的任何設備上都有麥克風,則可以使用它來讀取從計算機發出的任何聲音。然后,您可以將要錄制的音頻幀與要查找的聲音的聲音文件進行比較


當然,這使得它非常容易受到背景噪音的影響,因此不知何故,您將不得不將其過濾掉。


下面是使用 PyAudio 和 wave 庫的示例:


import pyaudio

import wave


wf = wave.open("websitSound.wav", "rb")

amountFrames = 100 # just an arbitrary number; could be anything

sframes = wf.readframes(amountFrames)


currentSoundFrame = 0


chunk = 1024  # Record in chunks of 1024 samples

sample_format = pyaudio.paInt16  # 16 bits per sample

channels = 2

fs = 44100  # Record at 44100 samples per second

seconds = 3


p = pyaudio.PyAudio()  # Create an interface to PortAudio



stream = p.open(format=sample_format,

                channels=channels,

                rate=fs,

                frames_per_buffer=chunk,

                input=True)



# Store data in chunks for 3 seconds

for i in range(0, int(fs / chunk * seconds)):

    data = stream.read(chunk)

    if data == sframes[currentSoundFrame]:

        currentSoundFrame += 1

        if currentSoundFrame == len(sframes): #the whole entire sound was played

            print("Sound was played!")

    frames.append(data)


# Stop and close the stream 

stream.stop_stream()

stream.close()

# Terminate the PortAudio interface

p.terminate()


查看完整回答
反對 回復 2022-09-06
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號