再會
我有一個 Python 專案,您可以在其中交談并獲得回復,例如聊天。該應用程式運行良好,現在我希望能夠安裝兩個麥克風并通過我的兩個麥克風與我的助手交談。
但問題是,我使用的是微軟語音服務,在他們的例子中,他們沒有展示使用兩個音頻流或與此相關的東西。我看到了他們關于使用 Java、C# 和 C 進行多音頻識別的主題。不支持python。
我的問題是,有什么方法可以將兩個或多個麥克風連接到我的筆記本電腦并同時使用兩個音頻流來獲得我的應用程式的回應?
我安裝了 python3.9,我的代碼只使用了 Microsoft 示例中的 identify_once() 函式。
我在想有什么方法可以像多執行緒一樣運行并從這些執行緒中收聽音頻,我不知道。我確實搜索了與此相關的主題,但人們解釋說使用 PyAudio 進行此操作,我使用 Microsoft 語音服務,因為我的語言不受支持。
任何幫助將不勝感激,對不起我的英語。
uj5u.com熱心網友回復:
對于此類問題,我們可以使用多個音頻通道陣列。有一項服務稱為“麥克風陣列推薦”。有不同的陣列通道,根據通道數,我們可以包括麥克風。我們可以包含 2、4、7 個通道的陣列。
2 個麥克風 - 這是一個線性通道。
查看以下檔案以了解間距和麥克風陣列。
檔案
您需要確保默認的 Microsoft Azure Kinect DK 已啟用。按照下面的python代碼,它處于運行狀態。
import pyaudio
import wave
import numpy as np
p = pyaudio.PyAudio()
# Find out the index of Azure Kinect Microphone Array
azure_kinect_device_name = "Azure Kinect Microphone Array"
index = -1
for i in range(p.get_device_count()):
print(p.get_device_info_by_index(i))
if azure_kinect_device_name in p.get_device_info_by_index(i)["name"]:
index = i
break
if index == -1:
print("Could not find Azure Kinect Microphone Array. Make sure it is properly connected.")
exit()
# Open the stream for reading audio
input_format = pyaudio.paInt32
input_sample_width = 4
input_channels = 7 #choose your channel count among 2,4,7
input_sample_rate = 48000
stream = p.open(format=input_format, channels=input_channels, rate=input_sample_rate, input=True, input_device_index=index)
# Read frames from microphone and write to wav file
with wave.open("output.wav", "wb") as outfile:
outfile.setnchannels(1) # We want to write only first channel from each frame
outfile.setsampwidth(input_sample_width)
outfile.setframerate(input_sample_rate)
time_to_read_in_seconds = 5
frames_to_read = time_to_read_in_seconds * input_sample_rate
total_frames_read = 0
while total_frames_read < frames_to_read:
available_frames = stream.get_read_available()
read_frames = stream.read(available_frames)
first_channel_data = np.fromstring(read_frames, dtype=np.int32)[0::7].tobytes()
outfile.writeframesraw(first_channel_data)
total_frames_read = available_frames
stream.stop_stream()
stream.close()
p.terminate()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/452679.html
