Code Monkey home page Code Monkey logo

mapbox-speech-swift's Introduction

Mapbox Speech

CircleCI codecov Carthage compatible CocoaPods SPM compatible

Mapbox Speech connects your iOS, macOS, tvOS, or watchOS application to the Mapbox Voice API. Take turn instructions from the Mapbox Directions API and read them aloud naturally in multiple languages. This library is specifically designed to work with mapbox-directions-swift as part of the Mapbox Navigation SDK for iOS.

This library is compatible with applications written in Swift. Version 2.0 was the last version of this library to support applications written in Objective-C or AppleScript.

Getting started

Specify the following dependency in your Carthage Cartfile:

github "mapbox/mapbox-speech-swift" ~> 2.1

Or in your CocoaPods Podfile:

pod 'MapboxSpeech', '~> 2.1'

Or in your Swift Package Manager Package.swift:

.package(url: "https://github.com/mapbox/mapbox-speech-swift.git", from: "2.1.1")

Then import MapboxSpeech or @import MapboxSpeech;.

Usage

You’ll need a Mapbox access token in order to use the API. If you’re already using the Mapbox Maps SDK for iOS or macOS SDK, Mapbox Speech automatically recognizes your access token, as long as you’ve placed it in the MBXAccessToken key of your application’s Info.plist file.

Basics

The main speech synthesis class is SpeechSynthesizer. Create a speech synthesizer object using your access token:

import MapboxSpeech

let speechSynthesizer = SpeechSynthesizer(accessToken: "<#your access token#>")

Alternatively, you can place your access token in the MBXAccessToken key of your application’s Info.plist file, then use the shared speech synthesizer object:

// main.swift
let speechSynthesizer = SpeechSynthesizer.shared

With the directions object in hand, construct a SpeechOptions or MBSpeechOptions object and pass it into the SpeechSynthesizer.audioData(with:completionHandler:) method.

// main.swift

let options = SpeechOptions(text: "hello, my name is Bobby")
speechSynthesizer.audioData(with: options) { (data: Data?, error: NSError?) in
    guard error == nil else {
        print("Error calculating directions: \(error!)")
        return
    }
    
    // Do something with the audio!
}

mapbox-speech-swift's People

Contributors

1ec5 avatar dependabot[bot] avatar frederoni avatar gwynne avatar jthramer avatar kried avatar maximalien avatar s2ler avatar udumft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-speech-swift's Issues

Read API base URL from Info.plist

If no host is passed into SpeechSynthesizer(accessToken:host:), the fallback hostname should be either api.mapbox.com or api.mapbox.cn depending on the value of MGLMapboxAPIBaseURL in Info.plist:

baseURLComponents.host = host ?? "api.mapbox.com"

This would be consistent with how we read the access token out of Info.plist:

let accessToken = accessToken ?? defaultAccessToken

This will make it easier for developers to keep their map, directions, and spoken instructions in sync, since SpeechSynthesizer.shared would automatically pick up the API endpoint specified in Info.plist. Developers who need a different value for the speech synthesizer can still override the API base URL when creating a separate SpeechSynthesizer instance.

/ref mapbox/MapboxGeocoder.swift#107
/cc @m-stephen @bsudekum

Incorrect Info.plist entries

The marketing version number in the Info.plist is set to 1.0 instead of 0.1. This affects a constant that’s exposed publicly:

<key>CFBundleShortVersionString</key>
<string>1.0</string>

Additionally, the bundle identifier is incorrectly set to com.Mapbox.MapboxSpeech instead of com.mapbox.MapboxSpeech:

PRODUCT_BUNDLE_IDENTIFIER = com.Mapbox.MapboxSpeech;

/cc @bsudekum

Require iOS 10.0 and above

Riding on the coattails of mapbox/mapbox-directions-swift#379, we should increase this library’s minimum deployment target to iOS 10.0 or above, macOS 10.12.0 or above, tvOS 10.0 or above, or watchOS 3.0 or above. This change isn’t strictly needed yet, but we’ll want to take care of it by v1.0.

/cc @mapbox/navigation-ios @frederoni

Thread Performance Checker Error in Xcode

Running into the following console log several times, but not always, when rout info is spoken.

Thread Performance Checker: Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. Investigate ways to avoid priority inversions
PID: 13929, TID: 913847

Backtrace

Screenshot 2024-04-02 at 12 27 36

Environment

Using SPM
MapboxSpeech 2.1.1
MapboxNavigation 2.17.0
MapboxCommon 23.8.6
Xcode Version 15.3 (15E204a)
iPhone Xr iOS 17.3.1

0 data bytes, no error in response from audioData

First time working with the speech SDK. Followed the (Swift) instructions in the README. Used my own access token. Everything appears to work (no errors), but the data returned is 0 bytes. Am I missing something?

image

Replace voice ID option with language option

The voiceId option couples this library too closely to the AWS SDK. I think instead the API should accept a language parameter, and we can map the language to our preferred Polly voice on the server side. The locale option in this library would default to the system locale, just as it does in MapboxDirections.swift.

/cc @bsudekum

Build universal framework target for Carthage

MapboxSpeech.xcodeproj currently has four separate framework targets, one for each platform, plus corresponding test targets and schemes. To streamline development both locally and downstream, we should combine them into a single framework target and test target. Downstream, only Carthage uses the Xcode project; it has supported universal frameworks since v0.9.

/ref mapbox/turf-swift#197
/cc @mapbox/navigation-ios

Announcement: main is now the default branch

main is now this repository’s default branch. Most development takes place on this branch, and releases will be based on this branch. For more context on the branch renaming, see github/renaming.

Like most GitHub repositories, this repository originally maintained master as the default branch. Now that v1.0 has been released, we’ve made main the default branch. All open pull requests now target the main branch; please target it going forward.

We’re aware that some developers have historically pointed their Podfiles or Cartfiles to the master branch. To avoid breaking your workflow or continuous integration builds, we’ve avoided deleting the master branch for now. However, that branch will only be kept in sync with the main branch on a best-effort basis. Eventually we expect to let that branch fall by the wayside.

This is also a good reminder that you should link to code within a repository using a permalink that specifies a specific commit or at least a specific branch, so that the link continues to function after a branch gets renamed or, more commonly, after a file gets renamed or code get shifted around.

/cc @mapbox/navigation-ios

Allow overriding SpeechOptions URL query parameters

SpeechOptions.path and SpeechOptions.params are internal. We should rename them to abridgedPath and urlQueryItems, respectively, and make them open, for consistency with RouteOptions in MapboxDirections. This will enable developers to pass in additional settings that aren’t supported by this library, such as beta parameters that it can’t support due to backwards compatibility concerns.

internal var params: [URLQueryItem] {

/ref mapbox/mapbox-directions-swift#343 mapbox/mapbox-directions-swift#461
/cc @mapbox/navigation-ios @browndp08 @Guardiola31337

Rename repository

MapboxSpeech.swift is consistent with MapboxDirections.swift, but mapbox-speech-swift would be a more normal repository name. The “.swift” syntax is unpleasant and sometimes triggers bugs in Xcode. The other Mapbox Swift libraries are still named in camel case with the .swift prefix, but that’s because we can’t easily change the CocoaPods pod name. Fortunately, this library’s podspec is named MapboxSpeech right off the bat, so we can rename this repository at any time without much fuss. So no rush. 😉

mapbox-speech-swift would be more consistent with mapbox-navigation-ios and turf-swift, in any case.

/cc @bsudekum

Publish documentation

MapboxSpeech’s public API is used in tandem with MapboxNavigation’s public API, so it should be documented and the documentation should be published somewhere easily accessible. Unlike with MapboxDirections, I think we can rely on the same simple GitHub Pages setup as in mapbox/turf-swift#162. MapboxSpeech is only a minor part of working with MapboxNavigation, and we don’t intend to productize it or the Mapbox Voice API as a standalone product.

/cc @mapbox/navigation-ios @mapbox/docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.