- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下内容录制音频:
localInput?.installTap(onBus: 0, bufferSize: 4096, format: localInputFormat) {
(buffer, time) -> Void in
let audioBuffer = self.audioBufferToBytes(audioBuffer: buffer)
let output = self.outputStream!.write(audioBuffer, maxLength: Int(buffer.frameLength))
if output > 0 {
print("\(#file) > \(#function) > \(output) bytes written from queue \(self.currentQueueName())")
}
else if output == -1 {
let error = self.outputStream!.streamError
print("\(#file) > \(#function) > Error writing to stream: \(error?.localizedDescription)")
}
}
我的 localInputFormat 如下:
self.localInput = self.localAudioEngine.inputNode
self.localAudioEngine.attach(self.localAudioPlayer)
self.localInputFormat = self.localInput?.inputFormat(forBus: 0)
self.localAudioEngine.connect(self.localAudioPlayer, to: self.localAudioEngine.mainMixerNode, format: self.localInputFormat)
audioBufferToBytes函数如下:
func audioBufferToBytes(audioBuffer: AVAudioPCMBuffer) -> [UInt8] {
let srcLeft = audioBuffer.floatChannelData![0]
let bytesPerFrame = audioBuffer.format.streamDescription.pointee.mBytesPerFrame
let numBytes = Int(bytesPerFrame * audioBuffer.frameLength)
// initialize bytes by 0
var audioByteArray = [UInt8](repeating: 0, count: numBytes)
srcLeft.withMemoryRebound(to: UInt8.self, capacity: numBytes) { srcByteData in
audioByteArray.withUnsafeMutableBufferPointer {
$0.baseAddress!.initialize(from: srcByteData, count: numBytes)
}
}
return audioByteArray
}
在其他设备上,当我收到数据时,我必须将其转换回来。因此,当它收到时,它会执行以下操作:
func bytesToAudioBuffer(_ buf: [UInt8]) -> AVAudioPCMBuffer {
let fmt = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 1, interleaved: true)
let frameLength = UInt32(buf.count) / fmt.streamDescription.pointee.mBytesPerFrame
let audioBuffer = AVAudioPCMBuffer(pcmFormat: fmt, frameCapacity: frameLength)
audioBuffer.frameLength = frameLength
let dstLeft = audioBuffer.floatChannelData![0]
buf.withUnsafeBufferPointer {
let src = UnsafeRawPointer($0.baseAddress!).bindMemory(to: Float.self, capacity: Int(frameLength))
dstLeft.initialize(from: src, count: Int(frameLength))
}
return audioBuffer
}
最后,我们播放音频数据:
self.audioPlayerQueue.async {
self.peerAudioPlayer.scheduleBuffer(audioBuffer)
if (!self.peerAudioPlayer.isPlaying && self.localAudioEngine.isRunning) {
self.peerAudioPlayer.play()
}
}
但是,在任一扬声器上,我都只能听到有人每半秒敲击一次麦克风的声音。不是他们实际上在说话或什么。我想这是由于我从音频缓冲区到字节的转换造成的,但我不确定。有人发现上述内容有任何问题吗?
谢谢。
最佳答案
如果有人对解决方案感兴趣,基本上问题是录音设备上的音频是 17640 字节,但为了流式传输它,它会将其分解成更小的片段,而在接收设备上我必须读取第一个 17640 字节字节然后播放音频。不播放收到的每一小块数据。
关于ios - 麦克风播放的音频断断续续,听起来像是空气吹入麦克风,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42701280/
是否可以使用回调来监听 CSS 变量的变化?像这样的东西: documentElement.addListener('css-var-main-background-color', () => {
我有应该运行laravel队列的docker镜像。在图像中,我有php artisan queue:listen命令,但是当我启动容器时,什么也没有发生,并且容器在运行。 这是基本图片 FROM ph
我正在尝试下载视频以在 exoplayer 中离线播放,但我不知道如何收听 onDownloadComplete。在 exoplayer 文档中,他们说 DownloadService是一个环绕 an
如果我在 View Controller 上有 2 个通知有 2 个这样的观察者,这是否合适: [NSNotificationCenter defaultCenter] addObserver:sel
尝试创建服务器-客户端应用程序时,我在设置服务器端连接时遇到了一些麻烦。设置套接字并bind()ing 套接字后,我的listen() 调用失败并显示错误消息 listen: Invalid argu
我有一个从不同模块更新的 UITextField(我将我的 UITextField 传递给上面提到的模块以填充它)。我需要一种方法来识别 UITextField 的文本值何时在 UITextField
假设我有单独的 Django 和 Tornado 应用程序。这就是我想要实现的目标: Django 收到一些 POST 请求并通知 Tornado 应用程序,以便 Tornado 应用程序可以向其连接
在一个模块上,我需要监听 url 的变化,所以我写了一个简单的代码: componentDidMount(){ history.listen( location => {
我想断言,当单击禁用按钮时,不会触发其 onClick 事件。我如何用 enzyme 来做到这一点?请参阅下面的示例代码。谢谢! sampleButton.jsx: import React from
我遇到了这个问题,我有一个部分(“.aboutsection”)一开始是隐藏的,需要在点击网页上的某个点时显示出来,然后开始为 .slideDown() 设置动画。我让它工作了,但每次我滚动到那个特定
我有一个关于 JS 中的键盘事件的问题。 首先,请不要回答我使用 jQuery 方法,我知道其中的大部分(绑定(bind)/解除绑定(bind),开/关,一个......)但我使用内部框架必须在没有
shiny 中是否有一个暴露的(甚至可能是非暴露的)函数会告诉我什么时候 react 失效?示例草稿: ui.R selectInput('select', ...) 服务器.R myfunc <-
我正在使用 PostgreSQL 数据库并应用它的 LISTEN/NOTIFY 功能。所以我的监听器在我的 AS(应用程序服务器)上,我在我的数据库上配置了触发器,这样当在表上执行 CRUD 操作时,
设置:一个简约的 Linux(华硕路由器上的 OpenWRT),一个 USB 键盘(假设我知道设备名称,如/dev/hiddev0) 一个目标:编写一个 python(或 shell,在这种情况下我可
我使用 Fragment 让用户在我的 Android 应用程序中输入信息。如果输入了信息,我希望在用户按下“后退”键时向用户发送警告。如果他确认要放弃更改,则必须弹出 Fragment。如果他取消放
这是我的 HTML/CSS 当前的样子: 这是我想要它的样子: 我如何修改下面的 HTML/CSS 以使其显示我想要的样子? HTML: CSS: .upda
我想使用 Heroku、PostgreSQL 和 Node.js,并将其设置为每当我在我的 postgres 数据库中添加一条记录时,Node.js 都会将该行的内容打印到控制台。 我正尝试按照这些指
在今天晚上之前我卸载了 vscode 并再次安装后一切正常我在尝试运行 npm run app 时遇到了这个问题我不知道如何解决这个问题我试图运行 vs 代码和命令提示符或 bash 使用以管理员身份
我目前正面临一个我无法解决的错误,我已经苦苦挣扎了几个小时。 我正在使用以下版本: Node :8.11.3 express :4.16.3 Jest :22.2.2 Mongoose :5.2.3
我正在尝试为网站上的特定 url 部署使用 node.js 开发的服务器。 已经有一个服务器可以覆盖网站上的所有网址,我希望我的唯一答案是 the_website_url/my_specific_ur
我是一名优秀的程序员,十分优秀!