我使用的JavaScript程序http://zaldzbugz.posterous.com/how-to-search-a-string-inside-uiwebview來解析HTML頁面,按照下述方式是否可以創建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代碼,我猜它在語音輸出中是一樣的)。 因爲我有很短的時間來解決,請幫助我... 在此先感謝..
謝謝你斯蒂芬。我沒有加載HTML頁面,並沒有必要在必要的JavaScript。 – iMeMyself