Skip to content

barisatamer/VaporGoogleCloudTTSProvider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VaporGoogleCloudTTSProvider

A Vapor 4 wrapper around SwiftGoogleCloudTTS

Installation 📦

To include it in your package, add the following to your Package.swift file.

let package = Package(
    name: "Project",
    dependencies: [
        ...
        .package(url: "https://github.com/barisatamer/VaporGoogleCloudTTSProvider.git", from: "0.0.8"),
        ],
        targets: [
            .target(name: "App", dependencies: ["VaporGoogleCloudTts", ... ])
        ]
    )

Setting the environment variable

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Usage 🚀

An example exists in vapor-example branch.

// routes.swift
func routes(_ app: Application) throws {
    let todoController = TodoController(googleCloudTtsClient: app.googleCloudTts.client)
    app.get("todos", use: todoController.index)
}

// TodoController.swift
import VaporGoogleCloudTts
import SwiftGoogleCloudTTS

struct TodoController {
    let googleCloudTtsClient: GoogleTTSClient
    
    init(googleCloudTtsClient: GoogleTTSClient) {
        self.googleCloudTtsClient = googleCloudTtsClient
    }
    
    func index(req: Request) throws -> EventLoopFuture<String> {
        let listVoicesRequest = Google_Cloud_Texttospeech_V1_ListVoicesRequest.with {
            $0.languageCode = "en-US"
        }
        return try googleCloudTtsClient.listVoices(request: listVoicesRequest).map { voicesResponse -> String in
            return voicesResponse.voices.map { $0.name }.joined(separator: "-")
        }
    }
}

About

A Vapor 4 wrapper around SwiftGoogleCloudTTS

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages