Я интегрировал массив Byte Byte Byte Websocket и Socket, и я использовал приведенный ниже код, чтобы воспроизводить звук из байта, который получает от сокета, и он работает нормально, но когда есть задержка из сокета, звук останавливается и не запускается снова. < /p>
Канал: mono
septore: 16000 < /em> < /p> : Получите размер байта со временем < /p>
Received binary data of size: 640 at time: 10:50:31.022
Received binary data of size: 640 at time: 10:50:31.059
Received binary data of size: 640 at time: 10:50:31.067
Received binary data of size: 640 at time: 10:50:31.086
Received binary data of size: 640 at time: 10:50:31.104
Received binary data of size: 640 at time: 10:50:31.124
Received binary data of size: 640 at time: 10:50:31.152 --- see the difference on this time only
Received binary data of size: 640 at time: 10:50:31.414
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.416
Received binary data of size: 640 at time: 10:50:31.416
< /code>
import Foundation
import AVFoundation
import Starscream
class AudioUnitPlayer {
var audioQueue: AudioQueueRef?
var audioFormat: AudioStreamBasicDescription
var isPlaying = false
init() {
audioFormat = AudioStreamBasicDescription(
mSampleRate: 16000,
mFormatID: kAudioFormatLinearPCM,
mFormatFlags: kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
mBytesPerPacket: 2, // 2 bytes per sample (16 bits)
mFramesPerPacket: 1, // 1 frame per packet
mBytesPerFrame: 2, // 2 bytes per frame (mono)
mChannelsPerFrame: 1, // Mono
mBitsPerChannel: 16, // 16 bits
mReserved: 0
)
}
func start() {
AudioQueueNewOutput(
&audioFormat,
audioQueueCallback,
Unmanaged.passUnretained(self).toOpaque(),
nil,
nil,
0,
&audioQueue
)
let numBuffers = 3
var buffers = [AudioQueueBufferRef?](repeating: nil, count: numBuffers)
for i in 0.. Int {
let audioData = buffer.pointee.mAudioData
let bytesToCopy = min(data.count, Int(buffer.pointee.mAudioDataBytesCapacity))
data.copyBytes(to: audioData.assumingMemoryBound(to: UInt8.self), count: bytesToCopy)
return bytesToCopy
}
func enqueuePCMData(_ data: Data) {
let chunkSize = 640
var offset = 0
while offset < data.count {
let end = min(offset + chunkSize, data.count)
let chunk = data.subdata(in: offset.. AudioQueueBufferRef? {
var buffer: AudioQueueBufferRef? = nil
let status = AudioQueueAllocateBuffer(audioQueue!, 640, &buffer)
guard status == noErr, let validBuffer = buffer else {
print("Failed to allocate audio buffer")
return nil
}
return validBuffer
}
}
func audioQueueCallback(
inUserData: UnsafeMutableRawPointer?,
inAQ: AudioQueueRef,
inBuffer: AudioQueueBufferRef
) {
print("Audio callback triggered")
let player = Unmanaged.fromOpaque(inUserData!).takeUnretainedValue()
inBuffer.pointee.mAudioDataByteSize = 0
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, nil)
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -ios-swift
Воспроизвести аудио из данных PCM и обрабатывать задержку PCM iOS Swift ⇐ IOS
Программируем под IOS
1743476572
Anonymous
Я интегрировал массив Byte Byte Byte Websocket и Socket, и я использовал приведенный ниже код, чтобы воспроизводить звук из байта, который получает от сокета, и он работает нормально, но когда есть задержка из сокета, звук останавливается и не запускается снова. < /p>
Канал: mono
septore: 16000 < /em> < /p> : Получите размер байта со временем < /p>
Received binary data of size: 640 at time: 10:50:31.022
Received binary data of size: 640 at time: 10:50:31.059
Received binary data of size: 640 at time: 10:50:31.067
Received binary data of size: 640 at time: 10:50:31.086
Received binary data of size: 640 at time: 10:50:31.104
Received binary data of size: 640 at time: 10:50:31.124
Received binary data of size: 640 at time: 10:50:31.152 --- see the difference on this time only
Received binary data of size: 640 at time: 10:50:31.414
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.415
Received binary data of size: 640 at time: 10:50:31.416
Received binary data of size: 640 at time: 10:50:31.416
< /code>
import Foundation
import AVFoundation
import Starscream
class AudioUnitPlayer {
var audioQueue: AudioQueueRef?
var audioFormat: AudioStreamBasicDescription
var isPlaying = false
init() {
audioFormat = AudioStreamBasicDescription(
mSampleRate: 16000,
mFormatID: kAudioFormatLinearPCM,
mFormatFlags: kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
mBytesPerPacket: 2, // 2 bytes per sample (16 bits)
mFramesPerPacket: 1, // 1 frame per packet
mBytesPerFrame: 2, // 2 bytes per frame (mono)
mChannelsPerFrame: 1, // Mono
mBitsPerChannel: 16, // 16 bits
mReserved: 0
)
}
func start() {
AudioQueueNewOutput(
&audioFormat,
audioQueueCallback,
Unmanaged.passUnretained(self).toOpaque(),
nil,
nil,
0,
&audioQueue
)
let numBuffers = 3
var buffers = [AudioQueueBufferRef?](repeating: nil, count: numBuffers)
for i in 0.. Int {
let audioData = buffer.pointee.mAudioData
let bytesToCopy = min(data.count, Int(buffer.pointee.mAudioDataBytesCapacity))
data.copyBytes(to: audioData.assumingMemoryBound(to: UInt8.self), count: bytesToCopy)
return bytesToCopy
}
func enqueuePCMData(_ data: Data) {
let chunkSize = 640
var offset = 0
while offset < data.count {
let end = min(offset + chunkSize, data.count)
let chunk = data.subdata(in: offset.. AudioQueueBufferRef? {
var buffer: AudioQueueBufferRef? = nil
let status = AudioQueueAllocateBuffer(audioQueue!, 640, &buffer)
guard status == noErr, let validBuffer = buffer else {
print("Failed to allocate audio buffer")
return nil
}
return validBuffer
}
}
func audioQueueCallback(
inUserData: UnsafeMutableRawPointer?,
inAQ: AudioQueueRef,
inBuffer: AudioQueueBufferRef
) {
print("Audio callback triggered")
let player = Unmanaged.fromOpaque(inUserData!).takeUnretainedValue()
inBuffer.pointee.mAudioDataByteSize = 0
AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, nil)
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79540972/play-audio-from-pcm-data-and-handle-pcm-delay-ios-swift[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия