LoginSignup
genkinaoko
@genkinaoko (元気なお香)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Untiy 2つのマイクを使用したい.

解決したいこと

PCにUSBマイクを2つ接続して, それぞれで音声データを分けて取得できるようにしたいです。

発生している問題・エラー

C#スクリプトを2つに分けて, それぞれ別のデバイス番号(Microphone番号)で接続するようにしましたが, 片方のマイクのみに接続が偏ります。

自分で試したこと

片方のスクリプト

void Start()
{
    var audio = GetComponent<AudioSource>();
    hairetu = new float[samplingRange];
    if((audio != null)&&(Microphone.devices.Length > 0)){
        string devName = Microphone.devices[0];
        audio.clip = Microphone.Start(devName, true, 10, 44100);
        audio.Play();
    }
}

// Update is called once per frame
void Update()
{
    var spectrum = GetComponent<AudioSource>().GetSpectrumData(samplingRange, 0, FFTWindow.Hamming);
    string bun = "";

もう片方のスクリプト

void Start()
{
    var audio2 = GetComponent<AudioSource>();
    hairetu = new float[samplingRange];
    if((audio2 != null)&&(Microphone.devices.Length > 0)){
        string devName2 = Microphone.devices[1];
        audio2.clip = Microphone.Start(devName2, true, 10, 44100);
        audio2.Play();
    }
}

// Update is called once per frame
void Update()
{
    var spectrum = GetComponent<AudioSource>().GetSpectrumData(samplingRange, 0, FFTWindow.Hamming);
    string bun2 = "";

一つのゲームシーンに複数の効果音(BGM)をAudioSourceで実装することが可能なため,
理論的には複数マイクの接続も可能なように思われますが、如何なのでしょうか。
どなたか解決方法を教えてください。

0

2Answer

2つ目のスクリプトだけなら動くのですか?

    if((audio2 != null)&&(Microphone.devices.Length > 0)){
        string devName2 = Microphone.devices[1];

以下が気になりました。

  • Microphone.devices.Length > 0ですと、Lengthが2以上かは保証されません。
  • devName2は期待通りでしょうか?
0

もしかして、こういうこと?

ひとつ目
var audio = GetComponents<AudioSource>() [0];
ふたつ目
var audio2 = GetComponents<AudioSource>() [1];
0

Your answer might help someone💌