2017-05-23 4 views
0
私はメッセージバブルをタップするチャットを作成したい

のdidTapMessageBubbleAtIndexPath機能を使用する方法、その私が使用したコードは下のようであるJSQMessageはJSQMessageViewController

のテキスト部分を話す:

私が直面しています
public func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath) { 


    let speechUtterance = AVSpeechUtterance(string: messages[indexPath.item].text) 

    speechSynthesizer.speak(speechUtterance) 


} 

問題は、私は、バブルをタップしたときに関数が呼び出されるdoesnotということです。

答えて

1

は今

let synth = AVSpeechSynthesizer() 
var myUtterance = AVSpeechUtterance(string: "") 

public func collectionView(collectionView: JSQMessagesCollectionView, didTapMessageBubbleAtIndexPath indexPath: NSIndexPath) { 

     // Make sure you are actually getting the text in messages[indexPath.item].text 

     myUtterance = AVSpeechUtterance(string: messages[indexPath.item].text) 
     myUtterance.rate = 0.3 
     synth.speakUtterance(myUtterance) 
} 

、これを試してみてください、あなたの問題のためにあなたがcellForItemAtIndexPathを書いていない可能性があります確認してください。これにより、didTapMessageBubbleAtIndexPathが呼び出されなくなります。

+0

問題は、メッセージの内容自体に実際にいました。テキストはヒンディー語で書かれていましたが、私はSpeechUtteranceの音声をヒンディー語に設定したことはありません。シンセサイザがテキスト言語を自動検出し、それに応じて音声を生成するように、どのように動的にすることができますか? –

関連する問題