当前位置:   article > 正文

Unity 二进制数据转换为AudioClip_unity audioclip.create

unity audioclip.create
  1. public static class NAudioPlayer
  2. {
  3. public static AudioClip FromMp3Data(byte[] data)
  4. {
  5. MemoryStream mp3stream = new MemoryStream(data);
  6. Mp3FileReader mp3audio = new Mp3FileReader(mp3stream);
  7. WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(mp3audio);
  8. WAV wav = new WAV(AudioMemStream(waveStream).ToArray());
  9. AudioClip audioClip;
  10. if (wav.ChannelCount == 2) {
  11. audioClip = AudioClip.Create("Audio File Name", wav.SampleCount, 2, wav.Frequency, false);
  12. audioClip.SetData(wav.StereoChannel, 0);
  13. } else {
  14. audioClip = AudioClip.Create("Audio File Name", wav.SampleCount, 1, wav.Frequency, false);
  15. audioClip.SetData(wav.LeftChannel, 0);
  16. }
  17. return audioClip;
  18. }
  19. private static MemoryStream AudioMemStream(WaveStream waveStream)
  20. {
  21. MemoryStream outputStream
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/127058
推荐阅读
相关标签
  

闽ICP备14008679号