internal static AudioDataEventArgs FromByateArray(byte[] arBytes, int len) { AudioDataEventArgs retVal = new AudioDataEventArgs(len); Array.Copy(arBytes, retVal.AudioData, len); return(retVal); }
public Task ReadAudioFile() { return(Task.Factory.StartNew(() => { using (FileStream fs = File.Open(this.filePath, FileMode.Open)) { using (BufferedStream bs = new BufferedStream(fs, BUFFER_SIZE)) { int byteRead; byte[] buffer = new byte[BUFFER_SIZE]; while ((byteRead = bs.Read(buffer, 0, BUFFER_SIZE)) > 0) { AudioBinaryRecived?.Invoke(this, AudioDataEventArgs.FromByateArray(buffer, byteRead)); log.Information($"{byteRead} bytes read from {filePath}"); Thread.Sleep(1000); } } } log.Information($"File data sent"); })); }
private static async void TtsClient_TextToSpeachResultsRecieved(object sender, AudioDataEventArgs e) { try { await File.WriteAllBytesAsync($"C:\\tmp\\{i}.wav", e.AudioData); await File.AppendAllTextAsync("C:\\tmp\\concat_files.txt", $"file '{i}.wav'\n"); i++; /* outFile.Write(e.AudioData, 0, e.AudioData.Length); * await outFile.FlushAsync();*/ } catch (Exception ex) { Log.Error(ex.ToString()); } }