Jak już pracował z parsowania HTML i text2speech tutaj można przejść z 2 kroki 1.Get Atrybut ciąg z pliku HTML z poniższym kodzie pracuje w iOS7+
jak na swoje perspektywy klienta: jeśli na rynku istnieje dowolne API dla HTML2Speech może być płatne lub zależne od tego API, jeśli go używasz. Podczas gdy natywny framework pomoże ci to, czego Ty/klient chcesz.
Krok 1:
[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil error:nil];
Następnie można przejść ten nadana smyczkowy AVSpeechUtterance
Krok 2: użycie poniżej sposób, aby uzyskać HTML2String:
/**
* "ConvertHTMLtoStrAndPlay" : This method will convert the HTML to String
synthesizer.
*
* @param aURLHtmlFilePath : "object of html file path"
*/
-(void)ConvertHTMLtoStrAndPlay:(UIButton*)aBtnPlayPause
isSpeechPaused:(BOOL)speechPaused
stringWithHTMLAttributes:(NSAttributedString*)aStrWithHTMLAttributes
{
if (synthesizer.speaking == NO && speechPaused == NO) {
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:aStrWithHTMLAttributes.string];
//utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
if (IS_ARABIC) {
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ar-au"];
}else{
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];
}
[synthesizer speakUtterance:utterance];
}
else{
[synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
if (speechPaused == NO) {
[synthesizer continueSpeaking];
} else {
[synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
}
i jak zwykle, gdy chcesz przestać używać kodu poniżej, aby zatrzymać Mowę.
/**
* "StopPlayWithAVSpeechSynthesizer" : this method will stop the playing of audio on the application.
*/
-(void)StopPlayWithAVSpeechSynthesizer{
// Do any additional setup after loading the view, typically from a nib.
[synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
Nadzieja Pomoże ci to uzyskać funkcję HTML2Speech.
Tak! ale czy masz format HTML? – amorbytes
Nie, nie ma poprawionego formatu pliku HTML. – CodeChanger
"chce dowolnego interfejsu API lub frameworka dostarczającego bezpośrednio funkcję HTML2Speech", każde API, które to zrobi, przetworzy podstawowy kod HTML i doda go do Text2Speech. Nie ma innego wyjścia. – Kevin