使用 Microsoft 语音服务监听 2 个或更多麦克风

发布于 2025-01-17 06:26:32 字数 457 浏览 5 评论 0原文

美好的一天,

我有一个 python 项目,你可以在其中交谈并获得回复,就像聊天一样。该应用程序运行良好,现在我希望能够安装两个麦克风并通过两个麦克风与我的助手交谈。

但问题是,我正在使用微软语音服务,在他们的示例中,他们没有展示如何使用两个音频流或与此相关的东西。我看到了他们关于使用 Java、C# 和 C++ 进行多重音频识别的主题。不支持Python。

我的问题是,有什么方法可以将两个或更多麦克风连接到我的笔记本电脑,并同时使用两个音频流来从我的应用程序获取响应?

我安装了 python3.9,我的代码仅使用 Microsoft 示例中的 recognize_once() 函数。

我在想有什么方法可以像多线程一样运行并监听这些线程的音频,我不知道。我确实搜索了与此相关的主题,但人们解释了使用 PyAudio 执行此操作,我使用微软语音服务,因为我的语言不受支持。

任何帮助将不胜感激,对不起我的英语。

Good day

I have a project in python where you can talk and get responses from, like a chat. The app is working great, now I want to be able to install two microphones and talk to my assistant from both of my microphones.

But the problem is, I'm using microsoft speech services, and in their examples they haven't shown about using two audio streams or something related to this. I saw their topic on multiple audio recognition with Java, C# and C++. No python is supported.

My question is, is there any way I can connect two or more microphones to my laptop and use two audio streams at the same time to get response from my app?

I have python3.9 installed and my code just uses recognize_once() function from Microsoft's examles.

I was thinking is there any way I can run like multi threads and listen for audio from those threads, I have no idea. I did search for topics related to this, but people explain doing this with PyAudio, I use microsoft speech services because my language isn't supported.

Any help would be appreciated, sorry for my english.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2025-01-24 06:26:32

对于此类问题,我们可以使用多音频通道数组。有一项服务称为“麦克风阵列推荐”。有不同的阵列通道,根据通道数,我们可以包括微
电话。我们可以包含 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()

For this kind of problem, we can use multiple audio channel array. There is a service called "Microphone array recommendations". There are different array channels and based on the channel count we can include the micro
phones. We can include the array of 2,4,7 channels.

2 Microphones - It's a linear channel.

Check the following document to know about the spacing and the microphone array.

Document

You need to make sure that the default Microsoft Azure Kinect DK is enabled or not. Follow the below python code, which is in the running state.

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文