I call this compiled exe from another Go program - to synthesize audio on Windows. SpVoice()
but not simpler SpeechSynthesizer API
because of crackles in the audio. Everything works fine but when I have in parallel not a ten but a few dozens copies of this program (each one is called from a goroutine) sometimes I am getting 3221225477. My C# code:
using System;
using System.Runtime.Serialization;
using SpeechLib;
class Program {
static SpVoice synth = new SpVoice();
static SpMemoryStream wave = new SpMemoryStream();
static void Main(string[] args) {
synth.AudioOutputStream = wave;
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms720595(v%3Dvs.85)
wave.Format.Type = SpeechAudioFormatType.SAFT44kHz16BitMono;
using (var stdin = Console.OpenStandardInput()) {
using (var stdout = Console.OpenStandardOutput()) {
var m = (Message)new System
.Runtime
.Serialization
.Json
.DataContractJsonSerializer(typeof(Message)).ReadObject(stdin);
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms722610(v%3dvs.85)
foreach(SpObjectToken voice in synth.GetVoices()) {
if (voice.GetDescription().Contains(m.Voice)) {
synth.Voice = voice;
}
}
synth.Speak(m.Text);
var wavBytes = (byte[])wave.GetData();
stdout.Write(wavBytes, 0, wavBytes.Length);
}
}
wave = new SpMemoryStream(); // Withoit reinit will concatenate
synth.AudioOutputStream = wave;
}
}
[DataContract]
class Message {
[DataMember]
public string Voice { get; set; }
[DataMember]
public string Text { get; set; }
}
I found that 3221225477
mean STATUS_ACCESS_VIOLATION
. I tried try/catch everything and write to logs but on such exit I found no records in Event Viewer. I run this on Windows Server 2019 on Google Cloud.
Update: I found that Wav returned from stdout even on this error.