使用 SampleDataEvent 实时修改 NetStream 中音频的声音
我正在使用 NetConnection 和 NetStream 传输音频。我知道您可以使用 Sound 对象实时修改示例数据,但是我找不到用于使用 NetStream 对象播放音频的 SampleDataEvent。有没有办法将音频从 NetStream 对象传递到 Sound 对象并修改该对象的声音?
编辑: 我愿意做任何类型的疯狂黑客,所以任何解决方案都可以!
I'm streaming audio using NetConnection and NetStream. I know that you can modify sample data in real-time with the Sound object, however I cannot find the SampleDataEvent for audio playing with the NetStream object. Is there a way to pass the audio from the NetStream object to a Sound object and modify the sound at that object instead?
Edit:
I'm willing to do any kind of crazy hacks, so any solution is OK!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要访问声音的字节码,如果使用 netstream,则只能通过将其传递给(请求)
NetStream.send()
/NetConnection.call()
除了正在传输的数据。否则,您将需要诸如Sound
或URLStream
的直接 url 之类的东西you need to access the bytecode of the sound, if using netstream it's possible only by passing it to (requesting it by)
NetStream.send()
/NetConnection.call()
in addition to the data being streamed. else you'll need something like a direct url for aSound
orURLStream
根据您正在寻找的质量,您可以将其牺牲为低比特率的单声道信号,您可以对其进行流式传输以在客户端将其作为 URLStream 获取,然后提供该数据URLStream 到空 Sound 对象的 SampleDataEvent,在运行时逐步进行。
额外的工作主要是在服务器端,将 MP3 解压缩为浮点数波形流(单通道 [单声道] 信号流或将两者组合成单声道的混合流),然后将其推送到您的客户端应用程序。
当 URLStream 加载时,将其下载的字节附加到 Sound 的 SampleDataEvent 上可用的 ByteArray(同时为其提供一些缓冲区“时间”来加载足够的波形数据)。对于从 URLStream 读取的每个单样本,您应该将相同的值写入 SampleDataEvent.data 对象两次(一次写入左通道,一次写入右通道)。
话虽如此,将类似 WAV 的声音流降级为单声道可能不足以减少带宽并覆盖广泛的目标受众。也许看看 AS3 的 OGG 库(应该存在)会是一个更好的选择,并且肯定应该支持解码部分下载的流。
Depending on the quality you're looking for, it you can sacrifice it down to a mono signal with low-bitrate, you may be able to stream it to obtain it as a URLStream on the client side, and then feed the data of that URLStream to a SampleDataEvent of an empty Sound object, progressively at runtime.
The extra work would mostly be on the server side, decompressing your MP3 to a Waveform stream of floating-numbers (a stream of a single-channel [mono] signal or a blend of the two combined to mono) and then pushing that out to your client side application.
As the URLStream gets loaded, append it's downloaded bytes to the ByteArray available on the Sound's SampleDataEvent (also give it some buffer "time" to load sufficient waveform data). For each mono-sample's read from the URLStream, you should write the same value twice to the SampleDataEvent.data object (once to the Left channel, once to the Right).
All this being said, downgrading the WAV-like sound stream to mono may not be sufficient to cut down on bandwidth and reach a wide target audience. Perhaps a look at an OGG library for AS3 (which should exists) would be a better alternative, and should certainly support decoding partially downloaded streams.