1

から取り出し、「転写」値:私は次のような結果から、「写し」の値を取得しようとしていますGoogleの音声API

{

transcript: "1 2 3 4" 
confidence: 0.902119 

words { 
    start_time { 
    nanos: 200000000 
    } 
    end_time { 
    nanos: 700000000 
    } 
    word: "1" 
} 
words { 
    start_time { 
    nanos: 700000000 
    } 
    end_time { 
    nanos: 900000000 
    } 
    word: "2" 
} 
words { 
    start_time { 
    nanos: 900000000 
    } 
    end_time { 
    seconds: 1 
    } 
    word: "3" 
} 
words { 
    start_time { 
    seconds: 1 
    } 
    end_time { 
    seconds: 1 
    nanos: 300000000 
    } 
    word: "4" 
} 

}

私が書いたコードそれを得る:

のresponse.resultsArrayのために! {

if let result = result as? StreamingRecognitionResult { 
    for alternative in result.alternativesArray { 
     if let alternative = alternative as? StreamingRecognitionResult { 
       textView.text = "\(alternative["transcript"])" 
      } 
      } 
      } 
        } 

私はtextview.textに値を入れしようとしているときに、私はというエラーを取得しています:

「タイプは 『StreamingRecognitionResult』は添字のメンバーを持っていません」。

助けてください。

答えて

0

ように、コードは、これに変更されます

for alternative in result.alternativesArray { 
    if let alternative1 = alternative as? SpeechRecognitionAlternative { 
     textView.text = "\(alternative1.transcript)" 
    } 
} 
2

キー行は次のとおり

let tmpBestResult = (response.resultsArray.firstObject as! StreamingRecognitionResult) 
let tmpBestAlternativeOfResult = tmpBestResult.alternativesArray.firstObject as! SpeechRecognitionAlternative 
let bestTranscript = tmpBestAlternativeOfResult.transcript 

streamAudioData(内部これらの線の配置)は以下の通りである:

SpeechRecognitionService.sharedInstance.streamAudioData(audioData,languageCode: self.selectedLangType.rawValue, 
                    completion: 

       { [weak self] (response, error) in 
        guard let strongSelf = self else { 
         return 
        } 

        if let error = error { 

         debugPrint(">>)) Process_delegate error >> \(error.localizedDescription)") 
         strongSelf.stopRecordingSpeech() 
         self?.delegate.conversionDidFail(errorMsg: error.localizedDescription) 
        } else if let response = response { 
         var finished = false 
         debugPrint(response) 
         for result in response.resultsArray! { 
          if let result = result as? StreamingRecognitionResult { 
           if result.isFinal { 
            finished = true 
           } 
          } 
         } 

         let tmpBestResult = (response.resultsArray.firstObject as! StreamingRecognitionResult) 
         let tmpBestAlternativeOfResult = tmpBestResult.alternativesArray.firstObject as! SpeechRecognitionAlternative 
         let bestTranscript = tmpBestAlternativeOfResult.transcript 
         strongSelf.delegate.conversionOnProcess(intermediateTranscript: bestTranscript!, isFinal: finished) 
         if finished { 
          //UI 
          strongSelf.stopRecordingSpeech() 
          strongSelf.delegate.conversionDidFinish(finalTranscript: bestTranscript!) 
         } 
        } 
      }) 

ハッピーコーディング;)

関連する問題