Exemplo n.º 1
0
def url(text,
        language,
        gender='f',
        pitch=100,
        volume=100,
        speed=90,
        encoding=''):  # disable escape by default
    """
  @param  text  unicode
  @param  language  str
  @param  gender  'f' or 'm'
  @param* pitch  int
  @param* volume  int
  @param* speed  int
  @param* encoding  str
  @return  unicode
  """
    config = LANGUAGE_SPEAKERS.get((language[:2], gender
                                    or 'f'))  # female by default
    if not config:
        return ''
    speakerId, host = config
    #if rate != 1:
    #  speed = int(speed * rate)
    if encoding:
        text = topercentencoding(text, encoding)
    return "http://%s/tts/mp3ttsV1.cgi?spk_id=%s&text_fmt=0&pitch=%s&volume=%s&speed=%s&wrapper=0&enc=0&text=%s" % (
        host, speakerId, pitch, volume, speed, text)
Exemplo n.º 2
0
 def query(self, text):
     """
 @param  text  unicode
 @return  {kw} or None
 """
     #text = text.encode(self.ENCODING, errors='ignore')
     text = sknetio.topercentencoding(text, encoding=self.ENCODING)
     if text:
         url = self._makeurl(text)
         h = self._fetch(url)
         if h:
             h = h.decode(self.ENCODING, errors='ignore')
             if h:
                 return self._iterparse(h)
Exemplo n.º 3
0
def createdata(id, dic, text, encoding='utf8', pitch=100, speed=100, volume=100):
  """
  @param  id  int
  @param  dic  int
  @param  text  unicode
  @param* encoding  str
  @param* pitch  int
  @param* speed  int
  @param* volume  int
  @return  unicode  post data
  """
  if len(text) > MAX_TEXT_LENGTH:
    text = text[:MAX_TEXT_LENGTH]
  text = topercentencoding(text)
  return "talkID=%s&dict=%s&pitch=%s&speed=%s&volume=%s&text=%s" % (id, dic, pitch, speed, volume, text) if text else ''
Exemplo n.º 4
0
 def query(self, text, path, limit=30, sort='new'):
     """
 @param  text  unicode
 @param  path  str  such as 'game', 'b' (BL)
 @yield  {kw}
 """
     #text = text.encode(self.ENCODING, errors='ignore')
     text = sknetio.topercentencoding(text, encoding=self.ENCODING)
     if text and path:
         url = self._makeurl(text=text, path=path, limit=limit, sort=sort)
         h = self._fetch(url)
         if h:
             h = h.decode(self.ENCODING, errors='ignore')
             if h and u'<font size="2">0件</font>' not in h:
                 return self._iterparse(h)
Exemplo n.º 5
0
def url(text, language, encoding='UTF-8'):
    """
  @param  text  unicode  not None
  @param  language  str  not None
  @param* encoding  utf8 or UTF-8 or None
  @return  unicode or str not None
  """
    if language:
        if encoding:
            text = topercentencoding(text, encoding)
        if text:
            language = baidudef.bdlang(language)
            # kor does not work for Korean orz
            language = language[:2]
            return API + "?ie=%s&lan=%s&text=%s" % (encoding, language, text)
    return ''
Exemplo n.º 6
0
def url(text, language, encoding=None):  # encoding is not needed
    """
  @param  text  unicode  not None
  @param  language  str  not None
  @param* encoding  utf8 or UTF-8 or None
  @return  unicode or str not None
  """
    if language:
        if encoding:
            text = topercentencoding(text, encoding)
        if text:
            if encoding:
                return API + "?client=t&ie=%s&tl=%s&q=%s" % (encoding,
                                                             language, text)
            else:
                return API + "?client=t&tl=%s&q=%s" % (language, text)
    return ''