我在http://zaldzbugz.posterous.com/how-to-search-a-string-inside-uiwebview使用 javascript 程序来解析 html 页面和以下方法
-(void)speakText:(NSString *)text
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"UIWebViewSearch" ofType:@"js" inDirectory:@""];
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
NSString *jsString = [[NSMutableString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
text =jsString;
NSMutableString *cleanString;
cleanString = [NSMutableString stringWithString:@""];
if([text length] > 1)
{
int x = 0;
while (x < [text length])
{
unichar ch = [text characterAtIndex:x];
[cleanString appendFormat:@"%c", ch];
x++;
}
}
if(cleanString == nil)
{ // string is empty
cleanString = [NSMutableString stringWithString:@""];
}
sound = flite_text_to_wave([cleanString UTF8String], voice);
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *recordingDirectory = [filePaths objectAtIndex: 0];
// Pick a file name
NSString *tempFilePath = [NSString stringWithFormat: @"%@/%s", recordingDirectory, "temp.wav"];
// save wave to disk
char *path;
path = (char*)[tempFilePath UTF8String];
cst_wave_save_riff(sound, path);
// Play the sound back.
NSError *err;
[audioPlayer stop];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:tempFilePath] error:&err];
[audioPlayer setDelegate:self];
//[audioPlayer prepareToPlay];
[audioPlayer play];
// Remove file
[[NSFileManager defaultManager] removeItemAtPath:tempFilePath error:nil];
delete_wave(sound);
}
将文本转换为语音字符串输入。,我在文本字段中听到一些编码格式而不是 html 文本(当我执行 NSLog(jsstring) 时,我得到了整个 javascript 代码,我猜它在语音输出中是一样的)。因为我有很短的时间来解决,请帮帮我...提前谢谢..