Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
protoc_plugins/
39 changes: 38 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
build:
PROTOS := $(shell find ./speechly -name *.proto)
SWIFT_PROTOS_DIR := ./Sources/SpeechlyAPI
SWIFT_BUILD_DIR := ./.build
SWIFT_LIB_VERSION := 1.0.0-alpha.20
SWIFT_PLUGINS_DIR := ./protoc_plugins
SWIFT_PROTOC_GEN_SWIFT := $(SWIFT_PLUGINS_DIR)/bin/protoc-gen-swift
SWIFT_PROTOC_GEN_GRPC_SWIFT := $(SWIFT_PLUGINS_DIR)/bin/protoc-gen-grpc-swift

build: build-swift
@echo "Generating code stubs"
@make -C go
@make -C python
@make -C javascript
.PHONY: build

build-swift: $(SWIFT_BUILD_DIR)
.PHONY: build-swift

clean-swift:
@rm -rf $(SWIFT_BUILD_DIR) $(SWIFT_PROTOS_DIR) $(SWIFT_PLUGINS_DIR) || true
.PHONY: clean-swift

$(SWIFT_BUILD_DIR): $(SWIFT_PROTOS_DIR)
@swift build
@touch $@

$(SWIFT_PROTOS_DIR): $(PROTOS) $(SWIFT_PLUGINS_DIR)
@mkdir -p $(SWIFT_PROTOS_DIR)
@protoc \
-I . \
--plugin=$(SWIFT_PROTOC_GEN_SWIFT) \
--plugin=$(SWIFT_PROTOC_GEN_GRPC_SWIFT) \
--swift_out="$(SWIFT_PROTOS_DIR)" \
--swift_opt=Visibility=Public \
--grpc-swift_out="$(SWIFT_PROTOS_DIR)" \
--grpc-swift_opt=Visibility=Public \
$(PROTOS)

$(SWIFT_PLUGINS_DIR):
@mkdir $(SWIFT_PLUGINS_DIR)
@curl -L https://github.com/grpc/grpc-swift/releases/download/$(SWIFT_LIB_VERSION)/protoc-grpc-swift-plugins-$(SWIFT_LIB_VERSION).zip -o $(SWIFT_PLUGINS_DIR)/plugins.zip
@unzip $(SWIFT_PLUGINS_DIR)/plugins.zip -d $(SWIFT_PLUGINS_DIR)
@rm $(SWIFT_PLUGINS_DIR)/plugins.zip
70 changes: 70 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "speechly-api",
products: [
.library(name: "SpeechlyAPI", targets: ["SpeechlyAPI"]),
],
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.20"),
],
targets: [
.target(
name: "SpeechlyAPI",
dependencies: [
.product(name: "GRPC", package: "grpc-swift"),
]
),
]
)
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,77 @@ This repository stores the definitions and generated code for Speechly public AP

Protocol buffers definitions are located in `speechly/`.

Generated Go code and the module is located in `go/`, Python code and package in `python/`, Javascript code and package in `javascript/`.
Generated Go code and the module is located in `go/`, Python code and package in `python/`, Javascript code and package in `javascript/` and Swift code in `Sources/`. Swift Package Manager requires the manifest to be in the root of the repository, hence why Swift code is not put into its dedicated subdirectory.

Make sure to check language-specific READMEs.

## Building

You can run the build for all languages with `make build` from the root of this repo.

## Using Swift stubs

You can add Swift stubs to your project using Swift Package Manager. Here's an example configuration:

```swift
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "my-package",
products: [
.executable(name: "SomeName", targets: ["SomeTarget"]),
],
dependencies: [
.package(url: "https://github.com/speechly/api.git", from: "1.0.0-alpha.1"),
],
targets: [
.target(
name: "SomeTarget",
dependencies: [
.product(name: "SpeechlyAPI", package: "speechly-api"),
]),
]
)
```

Thereafter you can use the stubs in your code (you will most likely need to add `grpc-swift` and `swift-nio` dependencies to write gRPC clients):

```swift
import NIO
import GRPC
import SpeechlyAPI

class IdentityClient {
let client: SpeechlyAPI.Speechly_Identity_V1_IdentityClient

init() {
let group = GRPC.PlatformSupport.makeEventLoopGroup(loopCount: 1)
let channel = GRPC.ClientConnection.secure(group: group).connect(host: "api.speechly.com", port: 443)

self.client = SpeechlyAPI.Speechly_Identity_V1_IdentityClient(channel: channel)
}

func login(appId: String, deviceId: String) -> NIO.EventLoopFuture<String> {
let request = SpeechlyAPI.Speechly_Identity_V1_LoginRequest.with {
$0.appID = appId
$0.deviceID = deviceId
}

return self.client.login(request).response.map({ (response: SpeechlyAPI.Speechly_Identity_V1_LoginResponse) -> String in
return response.token
})
}

deinit {
let future = self.client.channel.close()

do {
try future.wait()
} catch {
print("Error closing gRPC channel: \(error)")
}
}
}
```
Loading