Created
January 17, 2017 03:40
-
-
Save tnayuki/19d492faf5d5d871fa87db6b9a8ea99b to your computer and use it in GitHub Desktop.
AquesTalk Unityプラグイン。バッファサイズは固定(手抜き)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
public class AquesTalk : MonoBehaviour { | |
[DllImport ("AquesTalkPlugin")] | |
private static extern int AquesTalk2Synthe(string koe, int speed, IntPtr data, int size); | |
private float[] buffer = new float[1 * 1024 * 1024]; | |
void Synthe(string koe) { | |
GCHandle handle = GCHandle.Alloc (buffer, GCHandleType.Pinned); | |
int size = AquesTalk2Synthe (koe, 100, handle.AddrOfPinnedObject (), buffer.Length); | |
handle.Free (); | |
float[] data = new float[size]; | |
Buffer.BlockCopy (buffer, 0, data, 0, sizeof(float) * size); | |
AudioClip audioClip = AudioClip.Create ("AquesTalk", size, 1, 8000, false, false); | |
audioClip.SetData (data, 0); | |
audio.clip = audioClip; | |
audio.Play (); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <AquesTalk2Eva/AquesTalk2.h> | |
extern "C" { | |
int AquesTalk2Synthe(const char *koe, int speed, float *data, int size) { | |
int wavSize; | |
unsigned char* wav = AquesTalk2_Synthe_Utf8(koe, speed, &wavSize, NULL); | |
for (int i = 0; i < std::min(size, (wavSize - 44) / 2); i++) { | |
short sample = *(wav + 44 + i * 2) + *(wav + 44 + i * 2 + 1) * 256; | |
*(data + i) = (float)sample / 32768.0; | |
} | |
AquesTalk2_FreeWave(wav); | |
return (wavSize - 44) / 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment