1

Im using iSpeech API. I've posted in their forums but there is not much activity over there. I can pass it a string and have the app speak it. But now I want to pass in an array of strings, say 5. I want the engine to speak those strings one after the other but it only speaks the first one. I decided to use NSOperationQueue so in my viewDidLoad I did:

//Create Queue
    queue = [[NSOperationQueue alloc] init];
    [queue setMaxConcurrentOperationCount:1];

And then later I do this:

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    //Set loop for 5 strings
    [self fetchStringsToSpeak:indexPath];
    

    }

    -(void)fetchStringsToSpeak:(NSIndexPath*)indexPath{

    int stringsToSpeak = 5;
    
    for (int counter = 0; counter < stringsToSpeak; counter++) {
    
        //Get the string
        NSDictionary *currentString = [self.stringsArray objectAtIndex:indexPath.row+counter];
    
        //3. Fill im text and image for cell
        NSString *string = [currentString objectForKey:@"text"];
    
        //Clean the string from URLs
        NSError *error;
        NSDataDetector *linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
        NSArray *matches = [linkDetector matchesInString:string options:0 range:NSMakeRange(0, [string length])];
        NSLog(@"matches %@", matches);
    
        if ([matches count] > 0) {
            for (NSTextCheckingResult *match in matches) {
                if ([match resultType] == NSTextCheckingTypeLink) {
                    NSString *linkToRemove = [[match URL] absoluteString];
                    self.cleanString = [string stringByReplacingOccurrencesOfString:linkToRemove withString:@""];
                    NSLog(@"Clean string: %@", self.cleanString);
    
                }
            }
        } else {
            NSLog(@"NO LINK");
            self.cleanString = string;
        } //END IF/ELSE
    
    NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(speakAString:) object:self.cleanString];
    [queue addOperation:operation];
    
    //Message back to the main thread
    [self performSelectorOnMainThread:@selector(taDah) withObject:nil waitUntilDone:YES];
    
    } //END FOR LOOP
    

    }

    • (void)speakAString:(NSString*)stringToSpeak { ISSpeechSynthesis *synthesis = [[ISSpeechSynthesis alloc] initWithText:stringToSpeak]; NSError *err; if(![synthesis speak:&err]) { NSLog(@"ERROR: %@", err); } self.cleanString = nil; }

It is passed the values by these methods:

It speaks the first one but then I get this:

Domain=com.ispeech.ispeechsdk.ErrorDomain Code=303 "The SDK is already performing synthesis or recognition. Wait for that to finish before starting another request." UserInfo=0xb54f2b0 {NSLocalizedDescription=The SDK is already performing synthesis or recognition. Wait for that to finish before starting another request.}

Why is the operation queue not waiting?

marciokoko
  • 4,988
  • 8
  • 51
  • 91

0 Answers0