Documentation
¶
Overview ¶
Package soundanalysis provides Go bindings for the SoundAnalysis framework.
Classify various sounds by analyzing audio files or streams.
Identify specific sounds in your app, such as laughter or applause, by creating an SNClassifySoundRequest to analyze an audio file or stream. Sound requests can identify over 300 sounds. Alternatively, you identify a custom set of sounds by providing the sound request with a custom Core ML model. You train a custom sound classification model by creating an [MLSoundClassifier] with audio data in Create ML.
Audio analyzers ¶
- Classifying Sounds in an Audio File: Identify individual sounds in a file, such as a recording, with an audio file analyzer.
- SNAudioFileAnalyzer: An analyzer that runs sound classification requests on an audio file. (SNRequest, SNResultsObserving)
- Classifying Sounds in an Audio Stream: Identify individual sounds in an audio data stream, such as from a microphone, with an audio stream analyzer.
- SNAudioStreamAnalyzer: An object you create to analyze a stream of audio data and provide the results to your app. (SNRequest, SNResultsObserving)
Sound classification requests ¶
- Classifying Live Audio Input with a Built-in Sound Classifier: Detect and identify hundreds of sounds by using a trained classifier.
- SNClassifySoundRequest: A request that classifies sound using a Core ML model. (SNClassifierIdentifier, SNTimeDurationConstraint)
- SNClassificationResult: A result that contains the highest-ranking classifications in a time range. (SNClassification)
Errors ¶
- SNErrorCode: The enumerated error codes that the Sound Analysis framework produces.
- SNErrorDomain: A string that identifies the Sound Analysis error domain.//
Key Types ¶
- SNAudioFileAnalyzer - An analyzer that runs sound classification requests on an audio file.
- SNAudioStreamAnalyzer - An object you create to analyze a stream of audio data and provide the results to your app.
- SNClassifySoundRequest - A request that classifies sound using a Core ML model.
- SNTimeDurationConstraint - Defines the time duration windows the request’s underlying sound classifier accepts with a range, or an array, of durations.
- SNClassificationResult - A result that contains the highest-ranking classifications in a time range.
- SNClassification - A type that pairs a sound classifier’s prediction with its confidence in that prediction.
Code generated from Apple documentation. DO NOT EDIT.
Index ¶
- Variables
- func NewBoolBlock(handler BoolHandler) (objc.ID, func())
- type BoolHandler
- type ISNAudioFileAnalyzer
- type ISNAudioStreamAnalyzer
- type ISNClassification
- type ISNClassificationResult
- type ISNClassifySoundRequest
- type ISNTimeDurationConstraint
- type SNAudioFileAnalyzer
- func (a SNAudioFileAnalyzer) AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
- func (a SNAudioFileAnalyzer) Analyze()
- func (a SNAudioFileAnalyzer) AnalyzeSync(ctx context.Context) (bool, error)
- func (a SNAudioFileAnalyzer) AnalyzeWithCompletionHandler(completionHandler BoolHandler)
- func (a SNAudioFileAnalyzer) Autorelease() SNAudioFileAnalyzer
- func (a SNAudioFileAnalyzer) CancelAnalysis()
- func (a SNAudioFileAnalyzer) Init() SNAudioFileAnalyzer
- func (a SNAudioFileAnalyzer) InitWithURLError(url foundation.NSURL) (SNAudioFileAnalyzer, error)
- func (a SNAudioFileAnalyzer) RemoveAllRequests()
- func (a SNAudioFileAnalyzer) RemoveRequest(request SNRequest)
- type SNAudioFileAnalyzerClass
- type SNAudioStreamAnalyzer
- func (a SNAudioStreamAnalyzer) AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
- func (a SNAudioStreamAnalyzer) AnalyzeAudioBufferAtAudioFramePosition(audioBuffer avfaudio.AVAudioBuffer, ...)
- func (a SNAudioStreamAnalyzer) Autorelease() SNAudioStreamAnalyzer
- func (a SNAudioStreamAnalyzer) CompleteAnalysis()
- func (a SNAudioStreamAnalyzer) Init() SNAudioStreamAnalyzer
- func (a SNAudioStreamAnalyzer) InitWithFormat(format avfaudio.AVAudioFormat) SNAudioStreamAnalyzer
- func (a SNAudioStreamAnalyzer) RemoveAllRequests()
- func (a SNAudioStreamAnalyzer) RemoveRequest(request SNRequest)
- type SNAudioStreamAnalyzerClass
- type SNClassification
- type SNClassificationClass
- type SNClassificationResult
- func (c SNClassificationResult) Autorelease() SNClassificationResult
- func (c SNClassificationResult) ClassificationForIdentifier(identifier string) ISNClassification
- func (c SNClassificationResult) Classifications() []SNClassification
- func (c SNClassificationResult) Init() SNClassificationResult
- func (c SNClassificationResult) TimeRange() coremedia.CMTimeRange
- type SNClassificationResultClass
- type SNClassifierIdentifier
- type SNClassifySoundRequest
- func NewClassifySoundRequestWithClassifierIdentifierError(classifierIdentifier SNClassifierIdentifier) (SNClassifySoundRequest, error)
- func NewClassifySoundRequestWithMLModelError(mlModel *coreml.MLModel) (SNClassifySoundRequest, error)
- func NewSNClassifySoundRequest() SNClassifySoundRequest
- func SNClassifySoundRequestFromID(id objc.ID) SNClassifySoundRequest
- func (c SNClassifySoundRequest) Autorelease() SNClassifySoundRequest
- func (c SNClassifySoundRequest) Init() SNClassifySoundRequest
- func (c SNClassifySoundRequest) InitWithClassifierIdentifierError(classifierIdentifier SNClassifierIdentifier) (SNClassifySoundRequest, error)
- func (c SNClassifySoundRequest) InitWithMLModelError(mlModel *coreml.MLModel) (SNClassifySoundRequest, error)
- func (c SNClassifySoundRequest) KnownClassifications() []string
- func (c SNClassifySoundRequest) OverlapFactor() float64
- func (c SNClassifySoundRequest) SetOverlapFactor(value float64)
- func (c SNClassifySoundRequest) SetWindowDuration(value coremedia.CMTime)
- func (c SNClassifySoundRequest) SetWindowDurationConstraint(value ISNTimeDurationConstraint)
- func (c SNClassifySoundRequest) WindowDuration() coremedia.CMTime
- func (c SNClassifySoundRequest) WindowDurationConstraint() ISNTimeDurationConstraint
- type SNClassifySoundRequestClass
- type SNErrorCode
- type SNRequest
- type SNRequestObject
- type SNResult
- type SNResultObject
- type SNResultsObserving
- type SNResultsObservingObject
- func (o SNResultsObservingObject) BaseObject() objectivec.Object
- func (o SNResultsObservingObject) RequestDidComplete(request SNRequest)
- func (o SNResultsObservingObject) RequestDidFailWithError(request SNRequest, error_ foundation.NSError)
- func (o SNResultsObservingObject) RequestDidProduceResult(request SNRequest, result SNResult)
- type SNTimeDurationConstraint
- func NewSNTimeDurationConstraint() SNTimeDurationConstraint
- func NewTimeDurationConstraintWithDurationRange(durationRange coremedia.CMTimeRange) SNTimeDurationConstraint
- func NewTimeDurationConstraintWithEnumeratedDurations(enumeratedDurations []foundation.NSValue) SNTimeDurationConstraint
- func SNTimeDurationConstraintFromID(id objc.ID) SNTimeDurationConstraint
- func (t SNTimeDurationConstraint) Autorelease() SNTimeDurationConstraint
- func (t SNTimeDurationConstraint) DurationRange() coremedia.CMTimeRange
- func (t SNTimeDurationConstraint) EnumeratedDurations() []foundation.NSValue
- func (t SNTimeDurationConstraint) Init() SNTimeDurationConstraint
- func (t SNTimeDurationConstraint) InitWithDurationRange(durationRange coremedia.CMTimeRange) SNTimeDurationConstraint
- func (t SNTimeDurationConstraint) InitWithEnumeratedDurations(enumeratedDurations []foundation.NSValue) SNTimeDurationConstraint
- func (t SNTimeDurationConstraint) Type() SNTimeDurationConstraintType
- type SNTimeDurationConstraintClass
- type SNTimeDurationConstraintType
Constants ¶
This section is empty.
Variables ¶
var ( // SNErrorDomain is a string that identifies the Sound Analysis error domain. // // See: https://developer.apple.com/documentation/SoundAnalysis/SNErrorDomain SNErrorDomain string )
Functions ¶
func NewBoolBlock ¶
func NewBoolBlock(handler BoolHandler) (objc.ID, func())
NewBoolBlock wraps a Go BoolHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
Types ¶
type BoolHandler ¶
type BoolHandler = func(bool)
BoolHandler handles A completion closure (Swift) or block (Objective-C) the analyzer calls when it finishes analyzing a file.
Used by:
type ISNAudioFileAnalyzer ¶
type ISNAudioFileAnalyzer interface {
objectivec.IObject
// Creates a new audio file analyzer.
InitWithURLError(url foundation.NSURL) (SNAudioFileAnalyzer, error)
// Adds a new analysis request to the audio file analyzer.
AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
// Removes an existing request from the audio file analyzer.
RemoveRequest(request SNRequest)
// Removes all the sound analysis requests from the audio file analyzer.
RemoveAllRequests()
// Analyzes the audio file synchronously.
Analyze()
// Analyzes the audio file asynchronously.
AnalyzeWithCompletionHandler(completionHandler BoolHandler)
// Cancels all the asynchronous sound analysis requests the analyzer is currently processing.
CancelAnalysis()
}
An interface definition for the SNAudioFileAnalyzer class.
Creating an Analyzer ¶
- ISNAudioFileAnalyzer.InitWithURLError: Creates a new audio file analyzer.
Managing Requests ¶
- ISNAudioFileAnalyzer.AddRequestWithObserverError: Adds a new analysis request to the audio file analyzer.
- ISNAudioFileAnalyzer.RemoveRequest: Removes an existing request from the audio file analyzer.
- ISNAudioFileAnalyzer.RemoveAllRequests: Removes all the sound analysis requests from the audio file analyzer.
Analyzing Data ¶
- ISNAudioFileAnalyzer.Analyze: Analyzes the audio file synchronously.
- ISNAudioFileAnalyzer.AnalyzeWithCompletionHandler: Analyzes the audio file asynchronously.
- ISNAudioFileAnalyzer.CancelAnalysis: Cancels all the asynchronous sound analysis requests the analyzer is currently processing.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer
type ISNAudioStreamAnalyzer ¶
type ISNAudioStreamAnalyzer interface {
objectivec.IObject
// Creates a new audio stream analyzer.
InitWithFormat(format avfaudio.AVAudioFormat) SNAudioStreamAnalyzer
// Adds a new analysis request to the audio stream analyzer.
AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
// Removes an existing request from the audio stream analyzer.
RemoveRequest(request SNRequest)
// Removes all the sound analysis requests from the audio stream analyzer.
RemoveAllRequests()
// Adds a new audio buffer to the analyzer’s larger stream buffer.
AnalyzeAudioBufferAtAudioFramePosition(audioBuffer avfaudio.AVAudioBuffer, audioFramePosition avfaudio.AVAudioFramePosition)
// Notifies the analyzer when it receives the final audio buffer.
CompleteAnalysis()
}
An interface definition for the SNAudioStreamAnalyzer class.
Creating an Analyzer ¶
- ISNAudioStreamAnalyzer.InitWithFormat: Creates a new audio stream analyzer.
Managing Requests ¶
- ISNAudioStreamAnalyzer.AddRequestWithObserverError: Adds a new analysis request to the audio stream analyzer.
- ISNAudioStreamAnalyzer.RemoveRequest: Removes an existing request from the audio stream analyzer.
- ISNAudioStreamAnalyzer.RemoveAllRequests: Removes all the sound analysis requests from the audio stream analyzer.
Analyzing Data ¶
- ISNAudioStreamAnalyzer.AnalyzeAudioBufferAtAudioFramePosition: Adds a new audio buffer to the analyzer’s larger stream buffer.
- ISNAudioStreamAnalyzer.CompleteAnalysis: Notifies the analyzer when it receives the final audio buffer.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer
type ISNClassification ¶
type ISNClassification interface {
objectivec.IObject
// A prediction label that’s one of the classifications a sound classifier’s underlying model defines.
Identifier() string
// The confidence value the model has in its prediction.
Confidence() float64
}
An interface definition for the SNClassification class.
Inspecting a Classification ¶
- ISNClassification.Identifier: A prediction label that’s one of the classifications a sound classifier’s underlying model defines.
- ISNClassification.Confidence: The confidence value the model has in its prediction.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassification
type ISNClassificationResult ¶
type ISNClassificationResult interface {
objectivec.IObject
SNResult
// The time span that corresponds to the result’s classifications.
TimeRange() coremedia.CMTimeRange
// A sorted array of the request’s top classification candidates.
Classifications() []SNClassification
// Returns the classification for an identifier.
ClassificationForIdentifier(identifier string) ISNClassification
}
An interface definition for the SNClassificationResult class.
Inspecting the Result ¶
- ISNClassificationResult.TimeRange: The time span that corresponds to the result’s classifications.
- ISNClassificationResult.Classifications: A sorted array of the request’s top classification candidates.
- ISNClassificationResult.ClassificationForIdentifier: Returns the classification for an identifier.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassificationResult
type ISNClassifySoundRequest ¶
type ISNClassifySoundRequest interface {
objectivec.IObject
SNRequest
// Creates a request that uses a custom sound classification model.
InitWithMLModelError(mlModel *coreml.MLModel) (SNClassifySoundRequest, error)
// Creates a request that uses the framework’s built-in sound classification model.
InitWithClassifierIdentifierError(classifierIdentifier SNClassifierIdentifier) (SNClassifySoundRequest, error)
// The amount of overlap between successive analysis windows when the model operates on a fixed-size audio block.
OverlapFactor() float64
SetOverlapFactor(value float64)
// The duration of the audio buffer the request sends to the underlying sound classifier for each prediction.
WindowDuration() coremedia.CMTime
SetWindowDuration(value coremedia.CMTime)
// A string array that contains every prediction label in the request’s underlying sound classifier model.
KnownClassifications() []string
// A range or list of sound duration times the request’s underlying sound classifier supports.
WindowDurationConstraint() ISNTimeDurationConstraint
SetWindowDurationConstraint(value ISNTimeDurationConstraint)
}
An interface definition for the SNClassifySoundRequest class.
Creating a Request ¶
- ISNClassifySoundRequest.InitWithMLModelError: Creates a request that uses a custom sound classification model.
- ISNClassifySoundRequest.InitWithClassifierIdentifierError: Creates a request that uses the framework’s built-in sound classification model.
Configuring a Request ¶
- ISNClassifySoundRequest.OverlapFactor: The amount of overlap between successive analysis windows when the model operates on a fixed-size audio block.
- ISNClassifySoundRequest.SetOverlapFactor
- ISNClassifySoundRequest.WindowDuration: The duration of the audio buffer the request sends to the underlying sound classifier for each prediction.
- ISNClassifySoundRequest.SetWindowDuration
Inspecting a Request ¶
- ISNClassifySoundRequest.KnownClassifications: A string array that contains every prediction label in the request’s underlying sound classifier model.
Instance Properties ¶
- ISNClassifySoundRequest.WindowDurationConstraint: A range or list of sound duration times the request’s underlying sound classifier supports.
- ISNClassifySoundRequest.SetWindowDurationConstraint
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest
type ISNTimeDurationConstraint ¶
type ISNTimeDurationConstraint interface {
objectivec.IObject
// An enumeration that tells you which constraint property to inspect.
Type() SNTimeDurationConstraintType
// A time duration range the request’s underlying sound classifier accepts.
DurationRange() coremedia.CMTimeRange
// An array of time durations the request’s underlying sound classifier accepts.
EnumeratedDurations() []foundation.NSValue
// Creates a constraint with a time duration range.
InitWithDurationRange(durationRange coremedia.CMTimeRange) SNTimeDurationConstraint
// Creates a constraint with discrete time durations.
InitWithEnumeratedDurations(enumeratedDurations []foundation.NSValue) SNTimeDurationConstraint
}
An interface definition for the SNTimeDurationConstraint class.
Inspecting a Constraint ¶
- ISNTimeDurationConstraint.Type: An enumeration that tells you which constraint property to inspect.
- ISNTimeDurationConstraint.DurationRange: A time duration range the request’s underlying sound classifier accepts.
- ISNTimeDurationConstraint.EnumeratedDurations: An array of time durations the request’s underlying sound classifier accepts.
Creating a Time Duration Constraint ¶
- ISNTimeDurationConstraint.InitWithDurationRange: Creates a constraint with a time duration range.
- ISNTimeDurationConstraint.InitWithEnumeratedDurations: Creates a constraint with discrete time durations.
See: https://developer.apple.com/documentation/SoundAnalysis/SNTimeDurationConstraint-c.class
type SNAudioFileAnalyzer ¶
type SNAudioFileAnalyzer struct {
objectivec.Object
}
An analyzer that runs sound classification requests on an audio file.
Overview ¶
Run an SNRequest on an audio file by creating an SNAudioFileAnalyzer. You can run the same sound analysis request on multiple file analyzers, and each analyzer can process multiple requests. An audio file analyzer generates an SNResult each time any of its active requests recognizes a sound.
Creating an Analyzer ¶
- SNAudioFileAnalyzer.InitWithURLError: Creates a new audio file analyzer.
Managing Requests ¶
- SNAudioFileAnalyzer.AddRequestWithObserverError: Adds a new analysis request to the audio file analyzer.
- SNAudioFileAnalyzer.RemoveRequest: Removes an existing request from the audio file analyzer.
- SNAudioFileAnalyzer.RemoveAllRequests: Removes all the sound analysis requests from the audio file analyzer.
Analyzing Data ¶
- SNAudioFileAnalyzer.Analyze: Analyzes the audio file synchronously.
- SNAudioFileAnalyzer.AnalyzeWithCompletionHandler: Analyzes the audio file asynchronously.
- SNAudioFileAnalyzer.CancelAnalysis: Cancels all the asynchronous sound analysis requests the analyzer is currently processing.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer
func NewAudioFileAnalyzerWithURLError ¶
func NewAudioFileAnalyzerWithURLError(url foundation.NSURL) (SNAudioFileAnalyzer, error)
Creates a new audio file analyzer.
url: A path to an audio file.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/init(url:)
func NewSNAudioFileAnalyzer ¶
func NewSNAudioFileAnalyzer() SNAudioFileAnalyzer
NewSNAudioFileAnalyzer creates a new SNAudioFileAnalyzer instance.
func SNAudioFileAnalyzerFromID ¶
func SNAudioFileAnalyzerFromID(id objc.ID) SNAudioFileAnalyzer
SNAudioFileAnalyzerFromID constructs a SNAudioFileAnalyzer from an objc.ID.
An analyzer that runs sound classification requests on an audio file.
func (SNAudioFileAnalyzer) AddRequestWithObserverError ¶
func (a SNAudioFileAnalyzer) AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
Adds a new analysis request to the audio file analyzer.
request: A sound analysis request.
observer: An SNResultsObserving instance that receives the analyzer’s results. The analyzer maintains a weak reference to the observer.
Discussion ¶
The method throws an error (Swift) or returns an error (Objective-C) if the analyzer is actively processing the file.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/add(_:withObserver:)
func (SNAudioFileAnalyzer) Analyze ¶
func (a SNAudioFileAnalyzer) Analyze()
Analyzes the audio file synchronously.
Discussion ¶
This method executes synchronously and may block the calling thread for a long time.
The audio file analyzer sends errors to each request’s results observer.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/analyze()
func (SNAudioFileAnalyzer) AnalyzeSync ¶
func (a SNAudioFileAnalyzer) AnalyzeSync(ctx context.Context) (bool, error)
AnalyzeSync is a synchronous wrapper around SNAudioFileAnalyzer.AnalyzeWithCompletionHandler. It blocks until the completion handler fires or the context is cancelled.
func (SNAudioFileAnalyzer) AnalyzeWithCompletionHandler ¶
func (a SNAudioFileAnalyzer) AnalyzeWithCompletionHandler(completionHandler BoolHandler)
Analyzes the audio file asynchronously.
completionHandler: A completion closure (Swift) or block (Objective-C) the analyzer calls when it finishes analyzing a file.
Discussion ¶
The method executes asynchronously and calls the completion handler after the analyzer finishes analyzing the entire file. The audio file analyzer sends errors to each request’s results observer.
If you call the SNAudioFileAnalyzer.CancelAnalysis method, the analyzer calls your completion handler and passes `false` because it can’t reach the end of the file.
func (SNAudioFileAnalyzer) Autorelease ¶
func (a SNAudioFileAnalyzer) Autorelease() SNAudioFileAnalyzer
Autorelease adds the receiver to the current autorelease pool.
func (SNAudioFileAnalyzer) CancelAnalysis ¶
func (a SNAudioFileAnalyzer) CancelAnalysis()
Cancels all the asynchronous sound analysis requests the analyzer is currently processing.
Discussion ¶
The method executes asynchronously, and when it completes, the analyzer calls the completion handler you provide to the SNAudioFileAnalyzer.AnalyzeWithCompletionHandler method.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/cancelAnalysis()
func (SNAudioFileAnalyzer) Init ¶
func (a SNAudioFileAnalyzer) Init() SNAudioFileAnalyzer
Init initializes the instance.
func (SNAudioFileAnalyzer) InitWithURLError ¶
func (a SNAudioFileAnalyzer) InitWithURLError(url foundation.NSURL) (SNAudioFileAnalyzer, error)
Creates a new audio file analyzer.
url: A path to an audio file.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/init(url:)
func (SNAudioFileAnalyzer) RemoveAllRequests ¶
func (a SNAudioFileAnalyzer) RemoveAllRequests()
Removes all the sound analysis requests from the audio file analyzer.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/removeAllRequests()
func (SNAudioFileAnalyzer) RemoveRequest ¶
func (a SNAudioFileAnalyzer) RemoveRequest(request SNRequest)
Removes an existing request from the audio file analyzer.
request: A sound analysis request.
Discussion ¶
You can remove a request while the analyzer is processing it. The analyzer stops sending results to the observer after the method removes the request.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioFileAnalyzer/remove(_:)
type SNAudioFileAnalyzerClass ¶
type SNAudioFileAnalyzerClass struct {
// contains filtered or unexported fields
}
func GetSNAudioFileAnalyzerClass ¶
func GetSNAudioFileAnalyzerClass() SNAudioFileAnalyzerClass
GetSNAudioFileAnalyzerClass returns the class object for SNAudioFileAnalyzer.
func (SNAudioFileAnalyzerClass) Alloc ¶
func (sc SNAudioFileAnalyzerClass) Alloc() SNAudioFileAnalyzer
Alloc allocates memory for a new instance of the class.
func (SNAudioFileAnalyzerClass) Class ¶
func (sc SNAudioFileAnalyzerClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNAudioStreamAnalyzer ¶
type SNAudioStreamAnalyzer struct {
objectivec.Object
}
An object you create to analyze a stream of audio data and provide the results to your app.
Overview ¶
Run an SNRequest on an audio stream by creating an SNAudioStreamAnalyzer. You can run the same sound analysis request on multiple stream analyzers, and each analyzer can process multiple requests. An audio file analyzer generates an SNResult each time any of its active requests recognizes a sound.
Creating an Analyzer ¶
- SNAudioStreamAnalyzer.InitWithFormat: Creates a new audio stream analyzer.
Managing Requests ¶
- SNAudioStreamAnalyzer.AddRequestWithObserverError: Adds a new analysis request to the audio stream analyzer.
- SNAudioStreamAnalyzer.RemoveRequest: Removes an existing request from the audio stream analyzer.
- SNAudioStreamAnalyzer.RemoveAllRequests: Removes all the sound analysis requests from the audio stream analyzer.
Analyzing Data ¶
- SNAudioStreamAnalyzer.AnalyzeAudioBufferAtAudioFramePosition: Adds a new audio buffer to the analyzer’s larger stream buffer.
- SNAudioStreamAnalyzer.CompleteAnalysis: Notifies the analyzer when it receives the final audio buffer.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer
func NewAudioStreamAnalyzerWithFormat ¶
func NewAudioStreamAnalyzerWithFormat(format avfaudio.AVAudioFormat) SNAudioStreamAnalyzer
Creates a new audio stream analyzer.
format: The audio format of an audio stream.
Discussion ¶
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/init(format:)
func NewSNAudioStreamAnalyzer ¶
func NewSNAudioStreamAnalyzer() SNAudioStreamAnalyzer
NewSNAudioStreamAnalyzer creates a new SNAudioStreamAnalyzer instance.
func SNAudioStreamAnalyzerFromID ¶
func SNAudioStreamAnalyzerFromID(id objc.ID) SNAudioStreamAnalyzer
SNAudioStreamAnalyzerFromID constructs a SNAudioStreamAnalyzer from an objc.ID.
An object you create to analyze a stream of audio data and provide the results to your app.
func (SNAudioStreamAnalyzer) AddRequestWithObserverError ¶
func (a SNAudioStreamAnalyzer) AddRequestWithObserverError(request SNRequest, observer SNResultsObserving) (bool, error)
Adds a new analysis request to the audio stream analyzer.
request: A sound analysis request.
observer: An SNResultsObserving instance that receives the analyzer’s results. The analyzer maintains a weak reference to the observer.
Discussion ¶
You can add requests to an analyzer that’s actively analyzing an audio stream. The analyzer throws an error (Swift) or returns NO (Objective-C) if it can’t accept the new request, such as a request with an audio format that doesn’t match the analyzer’s.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/add(_:withObserver:)
func (SNAudioStreamAnalyzer) AnalyzeAudioBufferAtAudioFramePosition ¶
func (a SNAudioStreamAnalyzer) AnalyzeAudioBufferAtAudioFramePosition(audioBuffer avfaudio.AVAudioBuffer, audioFramePosition avfaudio.AVAudioFramePosition)
Adds a new audio buffer to the analyzer’s larger stream buffer.
audioBuffer: The audio data buffer.
audioFramePosition: The frame position of the data in the buffer. The analyzer expects this parameter to monotonically increase with each call. Otherwise, the analyzer may reset its internal state to account for the jump in time.
Discussion ¶
Serialize all calls to this method on a dedicated dispatch queue to prevent blocking the calling thread. The audio stream analyzer sends errors to each request’s results observer.
The method handles audio buffers that vary in size. If necessary, the analyzer regroups the data to a block size the underlying Core ML model expects. The analyzer uses a fixed-size audio block from some audio analysis types and may call a request’s results observer one time or many times. The factors that affect the number of calls are:
- The input buffer size - The underlying model’s native analysis block size - The analyzer’s current state
By default, the analyzer processes data on the first audio channel in the audio stream. The analyzer converts the sample rate of the data if it doesn’t match the underlying model’s requirements.
func (SNAudioStreamAnalyzer) Autorelease ¶
func (a SNAudioStreamAnalyzer) Autorelease() SNAudioStreamAnalyzer
Autorelease adds the receiver to the current autorelease pool.
func (SNAudioStreamAnalyzer) CompleteAnalysis ¶
func (a SNAudioStreamAnalyzer) CompleteAnalysis()
Notifies the analyzer when it receives the final audio buffer.
Discussion ¶
Use this method for requests that provide final results when a stream reaches its end. The analyzer ignores any further calls to the SNAudioStreamAnalyzer.AnalyzeAudioBufferAtAudioFramePosition method.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/completeAnalysis()
func (SNAudioStreamAnalyzer) Init ¶
func (a SNAudioStreamAnalyzer) Init() SNAudioStreamAnalyzer
Init initializes the instance.
func (SNAudioStreamAnalyzer) InitWithFormat ¶
func (a SNAudioStreamAnalyzer) InitWithFormat(format avfaudio.AVAudioFormat) SNAudioStreamAnalyzer
Creates a new audio stream analyzer.
format: The audio format of an audio stream.
Discussion ¶
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/init(format:)
func (SNAudioStreamAnalyzer) RemoveAllRequests ¶
func (a SNAudioStreamAnalyzer) RemoveAllRequests()
Removes all the sound analysis requests from the audio stream analyzer.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/removeAllRequests()
func (SNAudioStreamAnalyzer) RemoveRequest ¶
func (a SNAudioStreamAnalyzer) RemoveRequest(request SNRequest)
Removes an existing request from the audio stream analyzer.
request: A sound analysis request.
Discussion ¶
You can remove a request while the analyzer is processing it. The analyzer stops sending results to the observer after the method removes the request.
See: https://developer.apple.com/documentation/SoundAnalysis/SNAudioStreamAnalyzer/remove(_:)
type SNAudioStreamAnalyzerClass ¶
type SNAudioStreamAnalyzerClass struct {
// contains filtered or unexported fields
}
func GetSNAudioStreamAnalyzerClass ¶
func GetSNAudioStreamAnalyzerClass() SNAudioStreamAnalyzerClass
GetSNAudioStreamAnalyzerClass returns the class object for SNAudioStreamAnalyzer.
func (SNAudioStreamAnalyzerClass) Alloc ¶
func (sc SNAudioStreamAnalyzerClass) Alloc() SNAudioStreamAnalyzer
Alloc allocates memory for a new instance of the class.
func (SNAudioStreamAnalyzerClass) Class ¶
func (sc SNAudioStreamAnalyzerClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNClassification ¶
type SNClassification struct {
objectivec.Object
}
A type that pairs a sound classifier’s prediction with its confidence in that prediction.
Overview ¶
An SNClassification represents a single sound classification prediction, and the sound classifier model’s confidence in that prediction.
Inspecting a Classification ¶
- SNClassification.Identifier: A prediction label that’s one of the classifications a sound classifier’s underlying model defines.
- SNClassification.Confidence: The confidence value the model has in its prediction.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassification
func NewSNClassification ¶
func NewSNClassification() SNClassification
NewSNClassification creates a new SNClassification instance.
func SNClassificationFromID ¶
func SNClassificationFromID(id objc.ID) SNClassification
SNClassificationFromID constructs a SNClassification from an objc.ID.
A type that pairs a sound classifier’s prediction with its confidence in that prediction.
func (SNClassification) Autorelease ¶
func (c SNClassification) Autorelease() SNClassification
Autorelease adds the receiver to the current autorelease pool.
func (SNClassification) Confidence ¶
func (c SNClassification) Confidence() float64
The confidence value the model has in its prediction.
Discussion ¶
The model assigns confidence values in the range `[0, 1.0]`, where `1.0` represents 100% confidence.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassification/confidence
func (SNClassification) Identifier ¶
func (c SNClassification) Identifier() string
A prediction label that’s one of the classifications a sound classifier’s underlying model defines.
Discussion ¶
An example `identifier` might be a string like `laughter` or `applause`. The sound classifier’s underlying model defines the possible string values, which are typically technical names that you don’t directly present in your app’s user interface.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassification/identifier
func (SNClassification) Init ¶
func (c SNClassification) Init() SNClassification
Init initializes the instance.
type SNClassificationClass ¶
type SNClassificationClass struct {
// contains filtered or unexported fields
}
func GetSNClassificationClass ¶
func GetSNClassificationClass() SNClassificationClass
GetSNClassificationClass returns the class object for SNClassification.
func (SNClassificationClass) Alloc ¶
func (sc SNClassificationClass) Alloc() SNClassification
Alloc allocates memory for a new instance of the class.
func (SNClassificationClass) Class ¶
func (sc SNClassificationClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNClassificationResult ¶
type SNClassificationResult struct {
objectivec.Object
}
A result that contains the highest-ranking classifications in a time range.
Overview ¶
An SNClassificationResult represents the predictions that a sound classification model made for a time span in an audio file or stream. Each result contains one or more classification predictions and a time range within the audio data.
An audio analyzer, such as SNAudioFileAnalyzer and SNAudioStreamAnalyzer, produces an SNClassificationResult each time it recognizes a sound for any of its SNClassifySoundRequest instances.
Inspecting the Result ¶
- SNClassificationResult.TimeRange: The time span that corresponds to the result’s classifications.
- SNClassificationResult.Classifications: A sorted array of the request’s top classification candidates.
- SNClassificationResult.ClassificationForIdentifier: Returns the classification for an identifier.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassificationResult
func NewSNClassificationResult ¶
func NewSNClassificationResult() SNClassificationResult
NewSNClassificationResult creates a new SNClassificationResult instance.
func SNClassificationResultFromID ¶
func SNClassificationResultFromID(id objc.ID) SNClassificationResult
SNClassificationResultFromID constructs a SNClassificationResult from an objc.ID.
A result that contains the highest-ranking classifications in a time range.
func (SNClassificationResult) Autorelease ¶
func (c SNClassificationResult) Autorelease() SNClassificationResult
Autorelease adds the receiver to the current autorelease pool.
func (SNClassificationResult) ClassificationForIdentifier ¶
func (c SNClassificationResult) ClassificationForIdentifier(identifier string) ISNClassification
Returns the classification for an identifier.
identifier: A sound classification label.
Return Value ¶
A sound classification with a corresponding identifier if it exists in the result; otherwise, `nil`.
Discussion ¶
The `identifier` parameter corresponds to the SNClassification.Identifier property in an SNClassification.
func (SNClassificationResult) Classifications ¶
func (c SNClassificationResult) Classifications() []SNClassification
A sorted array of the request’s top classification candidates.
Discussion ¶
SNClassificationResult sorts its classifications in descending confidence score order.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassificationResult/classifications
func (SNClassificationResult) Init ¶
func (c SNClassificationResult) Init() SNClassificationResult
Init initializes the instance.
func (SNClassificationResult) TimeRange ¶
func (c SNClassificationResult) TimeRange() coremedia.CMTimeRange
The time span that corresponds to the result’s classifications.
Discussion ¶
The time range’s CMTime values are the number of audio frames at the analyzer’s sample rate. Use these time indices to determine where, in time, the result corresponds to the original audio.
A result’s time range typically refers to audio older than its most recent audio because the request gathers the data into blocks before sending them to the model.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassificationResult/timeRange
type SNClassificationResultClass ¶
type SNClassificationResultClass struct {
// contains filtered or unexported fields
}
func GetSNClassificationResultClass ¶
func GetSNClassificationResultClass() SNClassificationResultClass
GetSNClassificationResultClass returns the class object for SNClassificationResult.
func (SNClassificationResultClass) Alloc ¶
func (sc SNClassificationResultClass) Alloc() SNClassificationResult
Alloc allocates memory for a new instance of the class.
func (SNClassificationResultClass) Class ¶
func (sc SNClassificationResultClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNClassifierIdentifier ¶
type SNClassifierIdentifier = string
SNClassifierIdentifier is an identifier that represents the versions of the framework’s sound classifier.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifierIdentifier
var ( // SNClassifierIdentifierVersion1 is version 1 of the sound classifier. // // See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifierIdentifier/version1 SNClassifierIdentifierVersion1 SNClassifierIdentifier )
type SNClassifySoundRequest ¶
type SNClassifySoundRequest struct {
objectivec.Object
}
A request that classifies sound using a Core ML model.
Overview ¶
An SNClassifySoundRequest represents a specific sound classification model. Analyze audio data with a sound classification model by:
- Creating an SNClassifySoundRequest, either with the Sound Analysis model, or by providing your custom Core ML model. - Adding the sound request to an SNAudioFileAnalyzer or SNAudioStreamAnalyzer to process an audio file or stream, respectively.
For more information about creating and using classify sound requests, see:
- Classifying Sounds in an Audio File - Classifying Sounds in an Audio Stream
Creating a Request ¶
- SNClassifySoundRequest.InitWithMLModelError: Creates a request that uses a custom sound classification model.
- SNClassifySoundRequest.InitWithClassifierIdentifierError: Creates a request that uses the framework’s built-in sound classification model.
Configuring a Request ¶
- SNClassifySoundRequest.OverlapFactor: The amount of overlap between successive analysis windows when the model operates on a fixed-size audio block.
- SNClassifySoundRequest.SetOverlapFactor
- SNClassifySoundRequest.WindowDuration: The duration of the audio buffer the request sends to the underlying sound classifier for each prediction.
- SNClassifySoundRequest.SetWindowDuration
Inspecting a Request ¶
- SNClassifySoundRequest.KnownClassifications: A string array that contains every prediction label in the request’s underlying sound classifier model.
Instance Properties ¶
- SNClassifySoundRequest.WindowDurationConstraint: A range or list of sound duration times the request’s underlying sound classifier supports.
- SNClassifySoundRequest.SetWindowDurationConstraint
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest
func NewClassifySoundRequestWithClassifierIdentifierError ¶
func NewClassifySoundRequestWithClassifierIdentifierError(classifierIdentifier SNClassifierIdentifier) (SNClassifySoundRequest, error)
Creates a request that uses the framework’s built-in sound classification model.
classifierIdentifier: A sound classifier version identifier, such as version1.
func NewClassifySoundRequestWithMLModelError ¶
func NewClassifySoundRequestWithMLModelError(mlModel *coreml.MLModel) (SNClassifySoundRequest, error)
Creates a request that uses a custom sound classification model.
mlModel: A Core ML sound classification model.
Discussion ¶
The model you provide must accept audio data as input and produce a classification dictionary output that contains the probability of each category. For example, you can generate a sound classifier model by creating an MLSoundClassifier and training it with your own audio files.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest/init(mlModel:)
func NewSNClassifySoundRequest ¶
func NewSNClassifySoundRequest() SNClassifySoundRequest
NewSNClassifySoundRequest creates a new SNClassifySoundRequest instance.
func SNClassifySoundRequestFromID ¶
func SNClassifySoundRequestFromID(id objc.ID) SNClassifySoundRequest
SNClassifySoundRequestFromID constructs a SNClassifySoundRequest from an objc.ID.
A request that classifies sound using a Core ML model.
func (SNClassifySoundRequest) Autorelease ¶
func (c SNClassifySoundRequest) Autorelease() SNClassifySoundRequest
Autorelease adds the receiver to the current autorelease pool.
func (SNClassifySoundRequest) Init ¶
func (c SNClassifySoundRequest) Init() SNClassifySoundRequest
Init initializes the instance.
func (SNClassifySoundRequest) InitWithClassifierIdentifierError ¶
func (c SNClassifySoundRequest) InitWithClassifierIdentifierError(classifierIdentifier SNClassifierIdentifier) (SNClassifySoundRequest, error)
Creates a request that uses the framework’s built-in sound classification model.
classifierIdentifier: A sound classifier version identifier, such as version1.
func (SNClassifySoundRequest) InitWithMLModelError ¶
func (c SNClassifySoundRequest) InitWithMLModelError(mlModel *coreml.MLModel) (SNClassifySoundRequest, error)
Creates a request that uses a custom sound classification model.
mlModel: A Core ML sound classification model.
Discussion ¶
The model you provide must accept audio data as input and produce a classification dictionary output that contains the probability of each category. For example, you can generate a sound classifier model by creating an MLSoundClassifier and training it with your own audio files.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest/init(mlModel:)
func (SNClassifySoundRequest) KnownClassifications ¶
func (c SNClassifySoundRequest) KnownClassifications() []string
A string array that contains every prediction label in the request’s underlying sound classifier model.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest/knownClassifications
func (SNClassifySoundRequest) OverlapFactor ¶
func (c SNClassifySoundRequest) OverlapFactor() float64
The amount of overlap between successive analysis windows when the model operates on a fixed-size audio block.
Discussion ¶
The property defaults to `0.5` (50%) and supports values in the range `[0.0, 1.0]`.
Sound analyses that use a fixed-size audio block typically benefit with an overlap factor that’s greater than zero. An overlap factor of `0.0` may negatively affect your sound classifier’s accuracy because a sound may span two analysis windows. However, an overlap factor of `0.5` ensures each sound aligns near the center of at least one analysis window.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest/overlapFactor
func (SNClassifySoundRequest) SetOverlapFactor ¶
func (c SNClassifySoundRequest) SetOverlapFactor(value float64)
func (SNClassifySoundRequest) SetWindowDuration ¶
func (c SNClassifySoundRequest) SetWindowDuration(value coremedia.CMTime)
func (SNClassifySoundRequest) SetWindowDurationConstraint ¶
func (c SNClassifySoundRequest) SetWindowDurationConstraint(value ISNTimeDurationConstraint)
func (SNClassifySoundRequest) WindowDuration ¶
func (c SNClassifySoundRequest) WindowDuration() coremedia.CMTime
The duration of the audio buffer the request sends to the underlying sound classifier for each prediction.
Discussion ¶
Configure the window duration with a value that satisfies the request’s SNClassifySoundRequest.WindowDurationConstraint.
The request sends larger audio buffer windows less frequently, which can make the classifications more accurate, but less precise in indicating when they occur. Requests with smaller buffer window durations sharpen the time resolution of each prediction, but send smaller audio buffers to the sound classifier.
See: https://developer.apple.com/documentation/SoundAnalysis/SNClassifySoundRequest/windowDuration
func (SNClassifySoundRequest) WindowDurationConstraint ¶
func (c SNClassifySoundRequest) WindowDurationConstraint() ISNTimeDurationConstraint
A range or list of sound duration times the request’s underlying sound classifier supports.
type SNClassifySoundRequestClass ¶
type SNClassifySoundRequestClass struct {
// contains filtered or unexported fields
}
func GetSNClassifySoundRequestClass ¶
func GetSNClassifySoundRequestClass() SNClassifySoundRequestClass
GetSNClassifySoundRequestClass returns the class object for SNClassifySoundRequest.
func (SNClassifySoundRequestClass) Alloc ¶
func (sc SNClassifySoundRequestClass) Alloc() SNClassifySoundRequest
Alloc allocates memory for a new instance of the class.
func (SNClassifySoundRequestClass) Class ¶
func (sc SNClassifySoundRequestClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNErrorCode ¶
type SNErrorCode int
See: https://developer.apple.com/documentation/SoundAnalysis/SNError/Code
const ( // SNErrorCodeInvalidFile: An error that indicates an audio file is invalid. SNErrorCodeInvalidFile SNErrorCode = 5 // SNErrorCodeInvalidFormat: An error that indicates the audio data’s format isn’t valid. SNErrorCodeInvalidFormat SNErrorCode = 3 // SNErrorCodeInvalidModel: An error that indicates the sound classifier’s underlying Core ML model is an invalid model type. SNErrorCodeInvalidModel SNErrorCode = 4 // SNErrorCodeOperationFailed: An error that occurs when the framework fails to analyze audio. SNErrorCodeOperationFailed SNErrorCode = 2 // SNErrorCodeUnknownError: An error that represents a failure that no other error handles. SNErrorCodeUnknownError SNErrorCode = 1 )
func (SNErrorCode) String ¶
func (e SNErrorCode) String() string
type SNRequest ¶
type SNRequest interface {
objectivec.IObject
}
A protocol that represents sound analysis requests.
See: https://developer.apple.com/documentation/SoundAnalysis/SNRequest
type SNRequestObject ¶
type SNRequestObject struct {
objectivec.Object
}
SNRequestObject wraps an existing Objective-C object that conforms to the SNRequest protocol.
func SNRequestObjectFromID ¶
func SNRequestObjectFromID(id objc.ID) SNRequestObject
SNRequestObjectFromID constructs a SNRequestObject from an objc.ID. The object is determined to conform to the protocol at runtime.
func (SNRequestObject) BaseObject ¶
func (o SNRequestObject) BaseObject() objectivec.Object
type SNResult ¶
type SNResult interface {
objectivec.IObject
}
A protocol that represents sound analysis results.
See: https://developer.apple.com/documentation/SoundAnalysis/SNResult
type SNResultObject ¶
type SNResultObject struct {
objectivec.Object
}
SNResultObject wraps an existing Objective-C object that conforms to the SNResult protocol.
func SNResultObjectFromID ¶
func SNResultObjectFromID(id objc.ID) SNResultObject
SNResultObjectFromID constructs a SNResultObject from an objc.ID. The object is determined to conform to the protocol at runtime.
func (SNResultObject) BaseObject ¶
func (o SNResultObject) BaseObject() objectivec.Object
type SNResultsObserving ¶
type SNResultsObserving interface {
objectivec.IObject
// Provides a new analysis result to your app with the specified time range.
//
// See: https://developer.apple.com/documentation/SoundAnalysis/SNResultsObserving/request(_:didProduce:)
RequestDidProduceResult(request SNRequest, result SNResult)
}
The interface your app implements to receive the results of an analysis request.
See: https://developer.apple.com/documentation/SoundAnalysis/SNResultsObserving
type SNResultsObservingObject ¶
type SNResultsObservingObject struct {
objectivec.Object
}
SNResultsObservingObject wraps an existing Objective-C object that conforms to the SNResultsObserving protocol.
func SNResultsObservingObjectFromID ¶
func SNResultsObservingObjectFromID(id objc.ID) SNResultsObservingObject
SNResultsObservingObjectFromID constructs a SNResultsObservingObject from an objc.ID. The object is determined to conform to the protocol at runtime.
func (SNResultsObservingObject) BaseObject ¶
func (o SNResultsObservingObject) BaseObject() objectivec.Object
func (SNResultsObservingObject) RequestDidComplete ¶
func (o SNResultsObservingObject) RequestDidComplete(request SNRequest)
Notifies your app when the analysis request completes normally.
request: The request that’s completing.
Discussion ¶
The analyzer calls this method when it finishes processing the request.
See: https://developer.apple.com/documentation/SoundAnalysis/SNResultsObserving/requestDidComplete(_:)
func (SNResultsObservingObject) RequestDidFailWithError ¶
func (o SNResultsObservingObject) RequestDidFailWithError(request SNRequest, error_ foundation.NSError)
Provides any errors that occur during processing of the request.
request: The request that produces the error.
error: The error that occurs during the request.
Discussion ¶
The analyzer stops processing a specific request when it encounters an error, and doesn’t call [RequestDidComplete].
func (SNResultsObservingObject) RequestDidProduceResult ¶
func (o SNResultsObservingObject) RequestDidProduceResult(request SNRequest, result SNResult)
Provides a new analysis result to your app with the specified time range.
request: The request that produces the result.
result: The result of the analysis request.
Discussion ¶
The analyzer calls this function each time a new analysis result is available. Different types of analyses may produce results at different rates, spanning different time ranges.
See: https://developer.apple.com/documentation/SoundAnalysis/SNResultsObserving/request(_:didProduce:)
type SNTimeDurationConstraint ¶
type SNTimeDurationConstraint struct {
objectivec.Object
}
Defines the time duration windows the request’s underlying sound classifier accepts with a range, or an array, of durations.
Overview ¶
Inspect the constraint’s SNTimeDurationConstraint.Type property first to determine whether to check SNTimeDurationConstraint.DurationRange or SNTimeDurationConstraint.EnumeratedDurations next.
Inspecting a Constraint ¶
- SNTimeDurationConstraint.Type: An enumeration that tells you which constraint property to inspect.
- SNTimeDurationConstraint.DurationRange: A time duration range the request’s underlying sound classifier accepts.
- SNTimeDurationConstraint.EnumeratedDurations: An array of time durations the request’s underlying sound classifier accepts.
Creating a Time Duration Constraint ¶
- SNTimeDurationConstraint.InitWithDurationRange: Creates a constraint with a time duration range.
- SNTimeDurationConstraint.InitWithEnumeratedDurations: Creates a constraint with discrete time durations.
See: https://developer.apple.com/documentation/SoundAnalysis/SNTimeDurationConstraint-c.class
func NewSNTimeDurationConstraint ¶
func NewSNTimeDurationConstraint() SNTimeDurationConstraint
NewSNTimeDurationConstraint creates a new SNTimeDurationConstraint instance.
func NewTimeDurationConstraintWithDurationRange ¶
func NewTimeDurationConstraintWithDurationRange(durationRange coremedia.CMTimeRange) SNTimeDurationConstraint
Creates a constraint with a time duration range.
durationRange: A range of time durations.
func NewTimeDurationConstraintWithEnumeratedDurations ¶
func NewTimeDurationConstraintWithEnumeratedDurations(enumeratedDurations []foundation.NSValue) SNTimeDurationConstraint
Creates a constraint with discrete time durations.
enumeratedDurations: An array of time durations.
func SNTimeDurationConstraintFromID ¶
func SNTimeDurationConstraintFromID(id objc.ID) SNTimeDurationConstraint
SNTimeDurationConstraintFromID constructs a SNTimeDurationConstraint from an objc.ID.
Defines the time duration windows the request’s underlying sound classifier accepts with a range, or an array, of durations.
func (SNTimeDurationConstraint) Autorelease ¶
func (t SNTimeDurationConstraint) Autorelease() SNTimeDurationConstraint
Autorelease adds the receiver to the current autorelease pool.
func (SNTimeDurationConstraint) DurationRange ¶
func (t SNTimeDurationConstraint) DurationRange() coremedia.CMTimeRange
A time duration range the request’s underlying sound classifier accepts.
func (SNTimeDurationConstraint) EnumeratedDurations ¶
func (t SNTimeDurationConstraint) EnumeratedDurations() []foundation.NSValue
An array of time durations the request’s underlying sound classifier accepts.
func (SNTimeDurationConstraint) Init ¶
func (t SNTimeDurationConstraint) Init() SNTimeDurationConstraint
Init initializes the instance.
func (SNTimeDurationConstraint) InitWithDurationRange ¶
func (t SNTimeDurationConstraint) InitWithDurationRange(durationRange coremedia.CMTimeRange) SNTimeDurationConstraint
Creates a constraint with a time duration range.
durationRange: A range of time durations.
func (SNTimeDurationConstraint) InitWithEnumeratedDurations ¶
func (t SNTimeDurationConstraint) InitWithEnumeratedDurations(enumeratedDurations []foundation.NSValue) SNTimeDurationConstraint
Creates a constraint with discrete time durations.
enumeratedDurations: An array of time durations.
func (SNTimeDurationConstraint) Type ¶
func (t SNTimeDurationConstraint) Type() SNTimeDurationConstraintType
An enumeration that tells you which constraint property to inspect.
See: https://developer.apple.com/documentation/SoundAnalysis/SNTimeDurationConstraint-c.class/type
type SNTimeDurationConstraintClass ¶
type SNTimeDurationConstraintClass struct {
// contains filtered or unexported fields
}
func GetSNTimeDurationConstraintClass ¶
func GetSNTimeDurationConstraintClass() SNTimeDurationConstraintClass
GetSNTimeDurationConstraintClass returns the class object for SNTimeDurationConstraint.
func (SNTimeDurationConstraintClass) Alloc ¶
func (sc SNTimeDurationConstraintClass) Alloc() SNTimeDurationConstraint
Alloc allocates memory for a new instance of the class.
func (SNTimeDurationConstraintClass) Class ¶
func (sc SNTimeDurationConstraintClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type SNTimeDurationConstraintType ¶
type SNTimeDurationConstraintType int
See: https://developer.apple.com/documentation/SoundAnalysis/SNTimeDurationConstraintType
const ( // SNTimeDurationConstraintTypeEnumerated: A constraint type that uses an array of time durations to define what a request’s underlying sound classifier accepts. SNTimeDurationConstraintTypeEnumerated SNTimeDurationConstraintType = 1 // SNTimeDurationConstraintTypeRange: A constraint type that uses a time duration range to define what a request’s underlying sound classifier accepts. SNTimeDurationConstraintTypeRange SNTimeDurationConstraintType = 2 )
func (SNTimeDurationConstraintType) String ¶
func (e SNTimeDurationConstraintType) String() string
Source Files
¶
- blocks.gen.go
- doc.gen.go
- enums.gen.go
- functions.gen.go
- generate.go
- global_vars.gen.go
- request_protocol.gen.go
- result_protocol.gen.go
- results_observing_protocol.gen.go
- sn_audio_file_analyzer.gen.go
- sn_audio_stream_analyzer.gen.go
- sn_classification.gen.go
- sn_classification_result.gen.go
- sn_classify_sound_request.gen.go
- sn_time_duration_constraint.gen.go
- typedefs.gen.go
- types.gen.go
- undefined_types.gen.go