This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ArticleView: UIView { | |
| @TitleLabel(text: "Property Wrappers are fun!") | |
| var titleLabel: UILabel | |
| @ErrorLabel(text: "Something bad happened, rut roh!") | |
| var errorLabel: UILabel | |
| // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @propertyWrapper | |
| public class ErrorLabel { | |
| public var wrappedValue: UILabel | |
| public init(text: String) { | |
| self.wrappedValue = UILabel() | |
| wrappedValue.text = text | |
| configureLabel() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @propertyWrapper | |
| public class TitleLabel { | |
| public var wrappedValue: UILabel | |
| public init(text: String) { | |
| self.wrappedValue = UILabel() | |
| wrappedValue.text = text | |
| configureLabel() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func processAudio(_ data: Data) { | |
| audioData.append(data) | |
| let chunkSize: Int = Int(0.1 * Constants.kSampleRate * 2) | |
| if audioData.count > chunkSize { | |
| speechService.stream(audioData) { [weak self] response in | |
| guard let self = self else { return } | |
| DispatchQueue.main.async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func stream(_ data: Data, | |
| completion: ((Google_Cloud_Speech_V1_StreamingRecognizeResponse) -> Void)? = nil) { | |
| if !isStreaming { | |
| call = client.streamingRecognize { (response) in | |
| completion?(response) | |
| } | |
| isStreaming = true | |
| let config = Google_Cloud_Speech_V1_RecognitionConfig.with { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client = Google_Cloud_Speech_V1_SpeechClient(channel: channel, | |
| defaultCallOptions: callOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var callOptions = CallOptions() | |
| callOptions.customMetadata.add(name: "X-Goog-Api-Key", | |
| value: Constants.kAPIKey) | |
| callOptions.customMetadata.add(name: "X-Ios-Bundle-Identifier", | |
| value: "com.SpeechToText-gRPC-iOS") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let group = PlatformSupport.makeEventLoopGroup(loopCount: 1) | |
| let channel = ClientConnection | |
| .secure(group: group) | |
| .connect(host: "speech.googleapis.com", port: 443) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Usage: instantiate Google_Cloud_Speech_V1_SpeechClient, then call methods of this protocol to make API calls. | |
| public protocol Google_Cloud_Speech_V1_SpeechClientProtocol { | |
| func recognize(_ request: Google_Cloud_Speech_V1_RecognizeRequest, callOptions: CallOptions?) -> UnaryCall<Google_Cloud_Speech_V1_RecognizeRequest, Google_Cloud_Speech_V1_RecognizeResponse> | |
| func longRunningRecognize(_ request: Google_Cloud_Speech_V1_LongRunningRecognizeRequest, callOptions: CallOptions?) -> UnaryCall<Google_Cloud_Speech_V1_LongRunningRecognizeRequest, Google_Longrunning_Operation> | |
| func streamingRecognize(callOptions: CallOptions?, handler: @escaping (Google_Cloud_Speech_V1_StreamingRecognizeResponse) -> Void) -> BidirectionalStreamingCall<Google_Cloud_Speech_V1_StreamingRecognizeRequest, Google_Cloud_Speech_V1_StreamingRecognizeResponse> | |
| } | |
| public final class Google_Cloud_Speech_V1_SpeechClient: GRPCClient, Google_Cloud_Speech_V1_SpeechClientProtocol { | |
| public let channel: GRPCChannel | |
| public var defaultCallOpti |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct Google_Cloud_Speech_V1_StreamingRecognizeResponse { | |
| /// If set, returns a [google.rpc.Status][google.rpc.Status] message that | |
| /// specifies the error for the operation. | |
| public var error: Google_Rpc_Status { | |
| get {return _error ?? Google_Rpc_Status()} | |
| set {_error = newValue} | |
| } | |
| /// Returns true if `error` has been explicitly set. | |
| public var hasError: Bool {return self._error != nil} |
NewerOlder