Files
iOS/Sources/App/Assist/Audio/CMSampleBuffer+AudioSamples.swift
Bruno Pantaleão Gonçalves 62764d6849 Add Assist native UI, widgets and shortcut (#2697)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<img width="704" alt="Screenshot 2024-04-04 at 12 56 36"
src="https://github.com/home-assistant/iOS/assets/5808343/134c4206-d837-4a4e-83b2-0e199be0eca9">
<img width="204" alt="Screenshot 2024-04-04 at 12 56 40"
src="https://github.com/home-assistant/iOS/assets/5808343/a7637388-3ad4-4e60-a7a4-774c37694592">
<img width="1512" alt="Screenshot 2024-04-04 at 11 14 14"
src="https://github.com/home-assistant/iOS/assets/5808343/a70e07b1-c5a1-47bc-b027-ca0beac36c64">


## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2024-04-09 09:54:50 +02:00

30 lines
902 B
Swift

import CoreMedia
import Foundation
import Shared
extension CMSampleBuffer {
func audioSamples() -> Data? {
guard let audioBuffer = CMSampleBufferGetDataBuffer(self) else {
Current.Log.error("Failed to get audio data buffer from sample buffer.")
return nil
}
var audioBufferDataPointer: UnsafeMutablePointer<Int8>?
var audioBufferDataLength = 0
let status = CMBlockBufferGetDataPointer(
audioBuffer,
atOffset: 0,
lengthAtOffsetOut: nil,
totalLengthOut: &audioBufferDataLength,
dataPointerOut: &audioBufferDataPointer
)
guard status == kCMBlockBufferNoErr else {
Current.Log.error("Failed to access audio data pointer.")
return nil
}
return Data(bytes: audioBufferDataPointer!, count: audioBufferDataLength)
}
}