iOS Text To Speech Api

Não consigo encontrar nada sobre isto. Há alguma aula de Siri ou API no iOS7 que te deixe fazer texto para o discurso? Tudo o que estou a tentar fazer é algo como o seguinte:

[siriInstance say:@"This is a test"];
E a Siri que o diga da minha aplicação.

Parece que devemos ser capazes de fazer isto, não? Parece uma coisa trivial.

Author: Ali Abbas, 2014-03-21

4 answers

Desde iOS 7 que tens uma nova Api TTS.

No Objectivo C

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Some text"];
[utterance setRate:0.2f];
[synthesizer speakUtterance:utterance];

Em Swift

let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "Some text")
utterance.rate = 0.2

Também podes mudar a voz assim :

utterance.voice = AVSpeechSynthesisVoice(language: "fr-FR")

E depois o speek

  • In Swift 2 synthesizer.speakUtterance(utterance)

  • In Swift 3 synthesizer.speak(utterance)

Não te esqueças de ... import AVFoundation

Métodos Úteis

Você pode parar ou pausar toda a fala usando estes dois métodos :

- (BOOL)pauseSpeakingAtBoundary:(AVSpeechBoundary)boundary;
- (BOOL)stopSpeakingAtBoundary:(AVSpeechBoundary)boundary;

O AVSpeechBoundary indica se o discurso deve parar ou parar imediatamente (AVSpeechBoundaryImmediate) ou deve parar ou parar após a palavra actualmente a ser falada (AVSpeechBoundaryWord).

Verifica o DOC do Avspeechsinthesizer.
 127
Author: Ali Abbas, 2017-09-11 12:38:56
Esta é a resposta de Ali ABBAS para ser usada num parque infantil.
import UIKit
import AVKit
import AVFoundation
import PlaygroundSupport

var str = "Hello, playground"

let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: str)
utterance.rate = 0.4
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")

//for playground only
let playerViewController = AVPlayerViewController()
PlaygroundPage.current.liveView = playerViewController.view
//

synthesizer.speak(utterance)    
 4
Author: Matt Bearson, 2017-06-19 23:56:25
Nunca fiz nenhum trabalho especificamente com a Siri. Posso estar errado, mas acho que integrar-me com o Siri é muito difícil usando o API privado.

Eu daria uma olhada no framework openears para IOS. Eu fiz algum trabalho básico com isso no passado e ele faz tanto o reconhecimento offline de fala e sintetiza fala/texto-para-fala

Isto ajuda-te.
 3
Author: Tim, 2016-06-28 11:18:51

Aqui irá encontrar uma aplicação de exemplo text to speech (TTS) (Objective-C) baseada em Isto

 0
Author: d1jhoni1b, 2016-08-04 09:12:35