11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityでVOICEROID+の出力に合わせて口パク

Last updated at Posted at 2017-05-28

すごい雑ですが、UnityとVOICEROID+でMMDモデルの口パクをするサンプルです。

口パクの元音はNETDUETTOを使ってます。(最初にログ見て手書きで選びます。)
定数は私の環境下での調整値です。

using UnityEngine;


public class Mouth : MonoBehaviour
{
    void Start()
    {
        foreach (string device in Microphone.devices)
        {
            Debug.Log("Microphone.devices = " + device);
        }

        AudioSource audio = GetComponent<AudioSource>();
        audio.clip = Microphone.Start(Microphone.devices[1], true, 10, 44100);
    }

    void Update()
    {
        AudioSource audio = GetComponent<AudioSource>();
        float[] samples = new float[audio.clip.samples * audio.clip.channels];
        audio.clip.GetData(samples, 0);
        float vol = 0;
        for(int i = 0; i < samples.Length; i++)
        {
            vol += Mathf.Abs(samples[i]);
            samples[i] = samples[i] * 0.5F;
        }
        audio.clip.SetData(samples, 0);

        MMD4MecanimModel model = GetComponent<MMD4MecanimModel>();
        MMD4MecanimModelImpl.Morph morph = model.GetMorph("\u3042");
        morph.weight = Mathf.Min(1, vol / 50);
        
        print("vol = " + vol / 50);
    }
}

Microphone.devicesは日本語が読めないみたいなので、録音デバイスの名前から日本語を消してます。(私は空にした。)
これをしないと挙動がおかしかったり色々あるのでハマる可能性高いかもしれません。あと、要再起動です。
※不確かな話なのでご注意ください。

参考
http://www.jonki.net/entry/20130607/1370622815
http://tips.hecomi.com/entry/2014/11/11/021147
※もっと他にも色々見て回った気がするんですが、ごちゃごちゃで思い出せません……。みなさんありがとう。

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?