Mapbox Speech connecte votre application iOS, macOS, TVOS ou WatchOS à l'API vocale Mapbox. Profitez des instructions de l'API Mapbox Directions et lisez-les à haute voix naturellement dans plusieurs langues. Cette bibliothèque est spécialement conçue pour fonctionner avec Mapbox-Directions-Swift dans le cadre du SDK de navigation Mapbox pour iOS.
Cette bibliothèque est compatible avec les applications écrites dans Swift. La version 2.0 était la dernière version de cette bibliothèque pour prendre en charge les applications écrites dans Objective-C ou Applescript.
Spécifiez la dépendance suivante dans votre cartouche Carthage:
github "mapbox/mapbox-speech-swift" ~> 2.1
Ou dans votre cocoapods podfile:
pod 'MapboxSpeech' , '~> 2.1'Ou dans votre package Swift Package Manager.swift:
. package ( url : " https://github.com/mapbox/mapbox-speech-swift.git " , from : " 2.1.1 " ) import MapboxSpeech ou @import MapboxSpeech; .
Vous aurez besoin d'un jeton d'accès Mapbox pour utiliser l'API. Si vous utilisez déjà le SDK Mapbox Maps pour iOS ou MacOS SDK, Mapbox Speech reconnaît automatiquement votre jeton d'accès, tant que vous l'avez placé dans la clé MBXAccessToken du fichier Info.plist de votre application.
La principale classe de synthèse de la parole est SpeechSynthesizer . Créez un objet de synthétiseur vocal à l'aide de votre jeton d'accès:
import MapboxSpeech
let speechSynthesizer = SpeechSynthesizer ( accessToken : " <#your access token#> " ) Alternativement, vous pouvez placer votre jeton d'accès dans la clé MBXAccessToken du fichier Info.plist de votre application, puis utilisez l'objet Speech Synthesizer: partagé:
// main.swift
let speechSynthesizer = SpeechSynthesizer . shared Avec l'objet Directions en main, construisez un objet SpeechOptions ou MbSpeEchoptions et passez-le dans la méthode SpeechSynthesizer.audioData(with:completionHandler:) Méthode.
// 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!
}