複数のマイクをつないでキャラごとにリップシンク

## 概要

同じシーンに OVR Lipsync を適用したキャラが複数いる状態で、それぞれのキャラに別々のマイクの音声を割り当てる、を実現出来そうなヤツ。




<!--
https://qiita.com/sator_imaging/items/fc87297c4a464c548b02
-->




~~※まだ試してない。~~ 試した。

- [複数のマイクをつないでキャラごとにリップシンク（その２） - Qiita](https://qiita.com/sator_imaging/items/0dd9389aff86aca0218d)
   <iframe
      class="embed-card embed-webcard"
      scrolling="no"  frameborder="0"
      style="
         display: block;  border: none;
         margin: 10px 0px;
         width: 100%; height: 155px;
         max-width: 500px;
      "
      src="https://hatenablog-parts.com/embed?url=https://qiita.com/sator_imaging/items/0dd9389aff86aca0218d">
   </iframe>



## 指定したのマイクの音声を拾う方法

以下より。

- [How do I get Unity to playback a Microphone input in real time?](https://support.unity3d.com/hc/en-us/articles/206485253-How-do-I-get-Unity-to-playback-a-Microphone-input-in-real-time-)
   <iframe
      class="embed-card embed-webcard"
      scrolling="no"  frameborder="0"
      style="
         display: block;  border: none;
         margin: 10px 0px;
         width: 100%; height: 155px;
         max-width: 500px;
      "
      src="https://hatenablog-parts.com/embed?url=https://support.unity3d.com/hc/en-us/articles/206485253-How-do-I-get-Unity-to-playback-a-Microphone-input-in-real-time-">
   </iframe>


サンプルをちょっと編集。


```csharp
[SerializeField] string deviceName = "マイクのデバイス名をここに";

void Start()
{
   var audio = GetComponent<AudioSource>();
   if(null == audio)
   {
      return;
   }
   audio.clip = Microphone.Start(deviceName, true, 10, 44100);
   audio.loop = true;

   /* https://support.unity3d.com/hc/en-us/articles/206485253-How-do-I-get-Unity-to-playback-a-Microphone-input-in-real-time-
    *
    * To control latency you will also need to call Microphone.GetPosition(); and choose your desired latency sample rate.
    * If you want no latency you can set this to “0” samples before the audio starts to play.
    */
   // 指定したサンプル数だけディレイさせる。0 なら即時。
   //while (!(0 < Microphone.GetPosition(deviceName))){ }

   //Debug.Log("start playing... position is " + Microphone.GetPosition(deviceName));
   audio.Play();
}
```


デバイス名一覧をインスペクターに表示する。
Inspector 用のエディター拡張を作るほどでも無いので、表示された一覧からコピペする。





```csharp
#if UNITY_EDITOR
        public string[] microphoneDeviceNames;

        void Reset()
        {
            LoadMicrophoneDeviceNames();
        }

        void OnValidate()
        {
            LoadMicrophoneDeviceNames();
        }

        [ContextMenu("Load Microphone Device Names")]
        void LoadMicrophoneDeviceNames()
        {
            microphoneDeviceNames = Microphone.devices;
        }
#endif
```




### UnityEngine.Microphone リファレンス

- [Microphone.devices - Unity スクリプトリファレンス](https://docs.unity3d.com/ja/current/ScriptReference/Microphone-devices.html)

- [Microphone.Start - Unity スクリプトリファレンス](https://docs.unity3d.com/ja/current/ScriptReference/Microphone.Start.html)

- [Unity - Scripting API: Microphone.GetPosition](https://docs.unity3d.com/ScriptReference/Microphone.GetPosition.html)



--

#### こちらもどうぞ

- [#VTuber関連まとめ - Qiita](https://qiita.com/sator_imaging/items/5d3b4466a2a1539184d0)
   <iframe
      class="embed-card embed-webcard"
      scrolling="no"  frameborder="0"
      style="
         display: block;  border: none;
         margin: 10px 0px;
         width: 100%; height: 155px;
         max-width: 500px;
      "
      src="https://hatenablog-parts.com/embed?url=https://qiita.com/sator_imaging/items/5d3b4466a2a1539184d0">
   </iframe>