Closed jongfeelkim-VIRNECT closed 4 years ago
Using client library test
public class QuickStart
{
// The name of the local audio file to transcribe
public static string DEMO_FILE = "../resources/commercial_mono.wav";
public static void Main(string[] args)
{
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
//Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
//SampleRateHertz = 16000,
LanguageCode = "en",
}, RecognitionAudio.FromFile(DEMO_FILE));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
}
}
}
}
So, Audio encoding in Unity plan is...
Microphone record start set up 16000 sampling rate. Record to AudioSource.AudioClip and then save file to wav format.
audioSource.clip = Microphone.Start(microphoneDevice, true, 20, 16000);
To save file, use SavWav open source from gist. https://gist.github.com/darktable/2317063
It is convert from AudioClip to wav file.
QuickStart demo test from recorded wav file The saved file voice is "고려은단 비타민C" and translate to korean.
Open .wav file and read byte arrays. then convert from byte array to Base64Encoding string. https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionAudio?hl=ko
C# Convert class https://docs.microsoft.com/en-us/dotnet/api/system.convert.tobase64string?view=netframework-4.8
Supported audio encoding, not include wav. https://cloud.google.com/speech-to-text/docs/encoding
Use flac or mp3 (optional config) https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries
Convert audio data https://www.magellanic-clouds.com/blocks/en/guide/cloud-speech-api-audio-encoding/
In Unity