目测双声道 可以控制左右发声 实现立体环声
public static class AudioClipExtensions { /// <summary> /// 创建说话者特定的剪辑。 /// </summary> /// <returns>演讲者特定的剪辑。</returns> /// <param name="originalClip">原始剪辑。</param> /// <param name="amountOfChannels">数量的渠道</param> /// <param name="targetChannel">目标通道。</param> public static AudioClip CreateSpeakerSpecificClip(this AudioClip originalClip, int amountOfChannels, int targetChannel) { // 使用目标频道数量创建一个新的剪辑。 AudioClip clip = AudioClip.Create(originalClip.name, originalClip.samples, amountOfChannels, originalClip.frequency, false); // 音频数组。 float[] audioData = new float[originalClip.samples * amountOfChannels]; float[] originalAudioData = new float[originalClip.samples * originalClip.channels]; if (!originalClip.GetData(originalAudioData, 0)) return null; // 将音频从原始剪辑填充到目标频道。样品由通道(L0, R0, L1, R1等)交叉。 int originalClipIndex = 0; for (int i = targetChannel; i < audioData.Length; i += amountOfChannels) { audioData[i] = originalAudioData[originalClipIndex]; originalClipIndex += originalClip.channels; } if (!clip.SetData(audioData, 0)) return null; return clip; } }