A client that implements SpeechClientProtocol
on top of Speechly SLU API and an audio recorder.
public class Client
The client handles both the audio and the API streams, as well as API authentication, caching access tokens and dispatching data to delegate.
The client is ready to use once initialised.
AudioRecorderDelegate
, SluClientDelegate
, SpeechlyProtocol
Creates a new SpeechClient
.
public convenience init(appId: UUID? = nil, projectId: UUID? = nil, prepareOnInit: Bool = true, identityAddr: String = "grpc+tls://api.speechly.com", sluAddr: String = "grpc+tls://api.speechly.com", eventLoopGroup: EventLoopGroup = PlatformSupport.makeEventLoopGroup(loopCount: 1), delegateDispatchQueue: DispatchQueue = DispatchQueue(label: "com.speechly.Client.delegateQueue")) throws
- appId: Speechly application identifier. Eiither appId or projectId is needed.
- projectId: Speechly projectt identifier. Eiither appId or projectId is needed.
- prepareOnInit: Whether the client should prepare on initialisation. Preparing means initialising the audio stack and fetching the authentication token for the API.
- identityAddr: The address of Speechly Identity gRPC service. Defaults to Speechly public API endpoint.
- sluAddr: The address of Speechly SLU gRPC service. Defaults to Speechly public API endpoint.
- eventLoopGroup: SwiftNIO event loop group to use.
- delegateDispatchQueue:
DispatchQueue
to use for dispatching calls to the delegate.
init(appId:projectId:prepareOnInit:sluClient:identityClient:cache:audioRecorder:delegateDispatchQueue:)
Creates a new SpeechClient
.
public init(appId: UUID? = nil, projectId: UUID? = nil, prepareOnInit: Bool, sluClient: SluClientProtocol, identityClient: IdentityClientProtocol, cache: CacheProtocol, audioRecorder: AudioRecorderProtocol, delegateDispatchQueue: DispatchQueue) throws
- appId: Speechly application identifier. Eiither appId or projectId is needed.
- projectId: Speechly projectt identifier. Eiither appId or projectId is needed.
- prepareOnInit: Whether the client should prepare on initialisation. Preparing means initialising the audio stack and fetching the authentication token for the API.
- sluClient: An implementation of a client for Speechly SLU API.
- identityClient: An implementation of a client for Speechly Identity API.
- cache: An implementation of a cache protocol.
- audioRecorder: An implementaion of an audio recorder.
- delegateDispatchQueue:
DispatchQueue
to use for dispatching calls to the delegate.
var delegate: SpeechlyDelegate?
public func audioRecorderDidStop(_: AudioRecorderProtocol)
public func audioRecorderDidReceiveData(_: AudioRecorderProtocol, audioData: Data)
public func audioRecorderDidCatchError(_: AudioRecorderProtocol, error: Error)
public func sluClientDidCatchError(_ sluClient: SluClientProtocol, error: Error)
public func sluClientDidStopStream(_ sluClient: SluClientProtocol, status: GRPCStatus)
public func sluClientDidReceiveContextStart(_ sluClient: SluClientProtocol, contextId: String)
public func sluClientDidReceiveContextStop(_ sluClient: SluClientProtocol, contextId: String)
public func sluClientDidReceiveTentativeTranscript(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, transcript: SluClientDelegate.TentativeTranscript)
public func sluClientDidReceiveTentativeEntities(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, entities: SluClientDelegate.TentativeEntities)
public func sluClientDidReceiveTentativeIntent(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, intent: SluClientDelegate.TentativeIntent)
public func sluClientDidReceiveTranscript(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, transcript: SluClientDelegate.Transcript)
public func sluClientDidReceiveEntity(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, entity: SluClientDelegate.Entity)
public func sluClientDidReceiveIntent(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int, intent: SluClientDelegate.Intent)
public func sluClientDidReceiveSegmentEnd(_ sluClient: SluClientProtocol, contextId: String, segmentId: Int)
public func startContext(appId: String? = nil)
public func stopContext()
public func suspend()
public func resume() throws