예제 #1
0
 def talk(self, telegramBot, update):
     p = re.compile('([^ ]*) (.*)')
     query = (p.match(update.message.text).groups()[1] or '').strip()
     if query:
         self.logDebug(u'Talk (chat_id: %s, query: %s, source_language: pt)' % (update.message.chat_id, query or 'None'))
         audioFile = ExternalAPI.textToSpeech(query, language=self.language, encode='mp3')
         self.bot.sendAudio(chat_id=update.message.chat_id, audio=audioFile, performer=self.bot.getInfo().username)
예제 #2
0
 def jalkSearch(self, telegramBot, update):
     p = re.compile('([^ ]*) (.*)')
     query = (p.match(update.message.text).groups()[1] or '').strip()
     self.logDebug(u'Jalk search (chat_id: %s, query: %s)' % (update.message.chat_id, query or 'None'))
     jokes = ExternalAPI.searchJoke(query)
     if jokes:
         jokes = filter(lambda c: len(re.split('\W+', c, re.MULTILINE)) < 200, jokes)
         jokes = sorted(jokes, lambda x, y: len(x) - len(y))
         if jokes:
             joke = jokes[0]
             audioFile = ExternalAPI.textToSpeech(joke, language=self.language, encode='mp3')
             if os.path.exists(audioFile) and os.path.getsize(audioFile) > 0:
                 self.bot.sendAudio(chat_id=update.message.chat_id, audio=audioFile, performer=self.bot.getInfo().username)
             else:
                 self.bot.sendMessage(chat_id=update.message.chat_id, text=u'Não consigo contar')
         else:
             self.bot.sendMessage(chat_id=update.message.chat_id, text=u'Não encontrei piada curta')
예제 #3
0
 def textTextToSpeechAsOGG(self):
     sentence = 'ok'
     audioFile = ExternalAPI.textToSpeech(sentence, fromLanguage='en', encode='ogg')
     self.assertTrue(os.path.getsize(audioFile) > 0)