前面分享了一下Avalonia跨平台入门第三十九篇之再耍CEF;结果在我准备用Avalonia11的版本去玩耍时,直接给我提示:

1、果然不能用,为了新版本赶紧换思路:https://github.com/bkempinski/CefNet.Avalonia
2、来看看现在在Ubuntu下运行的最终效果:

3、接下来才是正题:语音播放,参考Avalonia跨平台入门第十九篇之语音播放:

4、初始化OpenAL:private void InitializeOpenAL(){ var device = ALC.OpenDevice(); var context = ALC.CreateContext(device, (int[])); ALC.MakeContextCurrent(context); _buffer = AL.GenBuffer(); _source = AL.GenSource(); GCHandle handle = GCHandle.Alloc(_audioData, GCHandleType.Pinned); try { AL.BufferData(_buffer, _format, handle.AddrOfPinnedObject(), _audioData.Length, _frequency); } finally { handle.Free(); } AL.Source(_source, ALSourcei.Buffer, _buffer); AL.Source(_source, ALSourceb.Looping, true);}5、关于读取 Wav文件:private void LoadWavFile(string filePath){ using (FileStream fs = File.OpenRead(filePath)) using (BinaryReader reader = new BinaryReader(fs)) { // RIFF header reader.ReadChars(4); // "RIFF" reader.ReadInt32(); // Chunk size reader.ReadChars(4); // "WAVE" // Format header reader.ReadChars(4); // "fmt " int fmtChunkSize = reader.ReadInt32(); // Subchunk1 size int audioFormat = reader.ReadInt16(); // Audio format (1 = PCM) int numChannels = reader.ReadInt16(); // Number of channels _frequency = reader.ReadInt32(); // Sample rate reader.ReadInt32(); // Byte rate reader.ReadInt16(); // Block align int bitsPerSample = reader.ReadInt16(); // Bits per sample // Validate format if (audioFormat != 1) throw new NotSupportedException("Only PCM WAV files are supported."); _format = (numChannels == 1 && bitsPerSample == 8) ? ALFormat.Mono8 : (numChannels == 1 && bitsPerSample == 16) ? ALFormat.Mono16 : (numChannels == 2 && bitsPerSample == 8) ? ALFormat.Stereo8 : (numChannels == 2 && bitsPerSample == 16) ? ALFormat.Stereo16 : throw new NotSupportedException("The specified WAV format is not supported."); // Move to data chunk reader.ReadChars(4); // "data" int dataSize = reader.ReadInt32(); _audioData = reader.ReadBytes(dataSize); }}6、结果又出现X11问题:

7、解决方案:把依赖复制到输出目录:OpenAL32.dllwrap_oal.dll8、在乌班图下出现问题:

9、解决方案:sudo apt-get install libopenal-dev /y
最终简单的效果先这样吧
;以后有时间的话,可以再去摸索一下更复杂的效果
;编程不息、Bug不止、无Bug、无生活;改bug的冷静、编码的激情、完成后的喜悦、挖坑的激动 、填坑的兴奋;这也许就是屌丝程序员的乐趣吧;今天就到这里吧;希望自己有动力一步一步坚持下去;生命不息,代码不止;大家抽空可以看看今天分享的效果,有好的意见和想法,可以在留言板随意留言;我看到后会第一时间回复大家,多谢大家的一直默默的关注和支持!