def guessTime(sSTR, sRATE, sFILEPATH, sLANG):
    '''
        Estimate time in seconds for speech to finish
    '''
    iRATE = ((int(sRATE) * 0.8) + 100) / 100
    iSecs = (1 + len(sSTR) / 18)
    retval = iRATE * iSecs
    if iSecs < 60:
        sCommand = "/usr/bin/espeak"
        if 'nt' in os.name.lower():
            sECE = "eSpeak/command_line/espeak.exe"
            sCommand = readtexttools.getWinFullPath(sECE)
        if os.path.isfile(sCommand):
            sWAVE = readtexttools.fsGetSoundFileName("", "", "TEMP")
            try:
                espeak_read_text_file.espkread(sFILEPATH, sLANG, "", "", sWAVE,
                                               "", "", "ShowWavtoSeconds", "",
                                               "", 50, 160)
                retval = iRATE * (readtexttools.WavtoSeconds(sWAVE))
            except (AttributeError, TypeError, ImportError):
                # Library is missing or incorrect version
                print('A local library for guessTime is missing or damaged.')
                retval = iRATE * iSecs
    print(retval)
    return retval
def guessTime(sSTR, sRATE, sFILEPATH, sLANG):
    '''
        Estimate time in seconds for speech to finish
    '''
    iRATE = ((int(sRATE) * 0.8) + 100) / 100
    iSecs = (1 + len(sSTR) / 18)
    retval = iRATE * iSecs
    if iSecs < 60:
        sCommand = "/usr/bin/espeak"
        if "windows" in platform.system().lower():
            sECE = "eSpeak/command_line/espeak.exe"
            sCommand = readtexttools.getWinFullPath(sECE)
        if os.path.isfile(sCommand):
            sWAVE = readtexttools.fsGetSoundFileName("", "", "TEMP")
            try:
                espeak_read_text_file.espkread(sFILEPATH, sLANG,
                                               "",
                                               "",
                                               sWAVE,
                                               "",
                                               "",
                                               "ShowWavtoSeconds",
                                               "",
                                               "",
                                               50,
                                               160)
                retval = iRATE * (readtexttools.WavtoSeconds(sWAVE))
            except(AttributeError, TypeError, ImportError):
                # Library is missing or incorrect version
                print('A local library for guessTime is missing or damaged.')
                retval = iRATE * iSecs
    print (retval)
    return retval
def festivalread(sFILEPATH, sVISIBLE, sAUDIBLE, sTMP0, sIMG1, sC):
    '''
  sTXTFILE - Text File to speak
  sVISIBLE- Use a graphical media player,or False for a command line media player
  sTMP0 - Name of desired output file
  sAUDIBLE - If false, then don't play the sound file
  sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
  '''
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "OUT")
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "TEMP")

    # Some apps throw an error if we try to overwrite a file, so delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if "windows" in platform.system().lower():
            if readtexttools.getWinFullPath("festival/text2wave"):
                sCommand = readtexttools.getWinFullPath(
                    "festival/festival.exe"
                ) + ' --script "' + readtexttools.getWinFullPath(
                    "festival/text2wave") + '"'
                s1 = sCommand + ' "' + sFILEPATH + '" -o "' + sTMP1 + '"'
                readtexttools.myossystem(s1)
                readtexttools.ProcessWaveMedia(sC, sTMP1, sIMG1, sOUT1,
                                               sAUDIBLE, sVISIBLE)
            else:
                # With Windows, this script only supports reading text aloud.
                sCommand = readtexttools.getWinFullPath(
                    "festival/festival.exe")
                s1 = sCommand + '--tts  "' + sFILEPATH + '"'
            readtexttools.myossystem(s1)
        else:
            sCommand = 'text2wave'
            # text2wave is an executable festival script
            s1 = sCommand + ' "' + sFILEPATH + '" -o "' + sTMP1 + '"'
            readtexttools.myossystem(s1)
            readtexttools.ProcessWaveMedia(sC, sTMP1, sIMG1, sOUT1, sAUDIBLE,
                                           sVISIBLE)
    except (IOError):
        print('I was unable to read!')
        print((str(err)))
        usage()
        sys.exit(2)
Beispiel #4
0
def picoread(sTXT, sLANG, sVISIBLE, sAUDIBLE, sTMP0, sIMG1, sB, sART, sDIM):
    '''
    sTXT - Actual text to speak. The file must be written as utf-8.
    sLANG - Supported two or four letter language code - defaults to US English
    sVISIBLE- Use a graphic media player, or False for invisible player
    sTMP0 - Name of desired output media file
    sAUDIBLE - If false, then don't play the sound file
    sIMG1 - a .png or .jpg file if required.
    sB - Commentary or title for post processing
    sPOSTPROCESS - Get information, play file, or convert a file
    sART - Artist or Author
    sDIM - Dimensions to scale photo '600x600'
    '''
    sOUT1 = ''
    if sLANG[:2].lower() == 'de':
        s = 'de-DE'
    elif sLANG[:2].lower() == 'en':
        if sLANG[-2:].upper() in 'AU;BD;BS;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT':
            s = 'en-GB'
        else:
            s = 'en-US'
    elif sLANG[:2].lower() == 'es':
        s = 'es-ES'
    elif sLANG[:2].lower() == 'fr':
        s = 'fr-FR'
    elif sLANG[:2].lower() == 'it':
        s = 'it-IT'
    else:
        s = 'en-US'
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'OUT')
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'TEMP')

    # Delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if 'nt' in os.name.lower():
            sCommand = readtexttools.getWinFullPath('opt/picosh.exe')
            if "de" in s.lower():
                s1 = ''.join(
                    [sCommand, ' –v de-DE_gl0 "', sTXT, '" "', sTMP1, '"'])
            else:  # Pico for Windows defaults to British English
                s1 = ''.join([sCommand, ' "', sTXT, '" "', sTMP1, '"'])
        else:
            sCommand = 'pico2wave'
            s1 = ''.join([sCommand, ' -l ', s, ' -w "', sTMP1, '"  ', sTXT])
        readtexttools.myossystem(s1)
        readtexttools.ProcessWaveMedia(sB, sTMP1, sIMG1, sOUT1, sAUDIBLE,
                                       sVISIBLE, sART, sDIM)
    except (IOError):
        print('I was unable to read!')
        usage()
        sys.exit(2)
def festivalread(sFILEPATH,sVISIBLE,sAUDIBLE,sTMP0,sIMG1,sC):
    '''
        sTXTFILE - Text File to speak
        sVISIBLE- Use a graphical media player,or False for a command line media player
        sTMP0 - Name of desired output file
        sAUDIBLE - If false, then don't play the sound file
        sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
        '''
    # Determine the output file name
    sOUT1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"OUT")
    # Determine the temporary file name
    sTMP1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"TEMP")
    
    # Some apps throw an error if we try to overwrite a file, so delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if "windows" in platform.system().lower():
            if readtexttools.getWinFullPath("festival/text2wave"):
                sCommand=readtexttools.getWinFullPath("festival/festival.exe")+' --script "'+readtexttools.getWinFullPath("festival/text2wave")+'"'
                s1=sCommand+' "'+sFILEPATH+'" -o "'+sTMP1+'"' 
                readtexttools.myossystem(s1)
                readtexttools.ProcessWaveMedia(sC,sTMP1,sIMG1,sOUT1,sAUDIBLE,sVISIBLE)
            else:
                # With Windows, this script only supports reading text aloud.
                sCommand=readtexttools.getWinFullPath("festival/festival.exe")
                s1=sCommand+ '--tts  "' + sFILEPATH+'"'
            readtexttools.myossystem(s1)
        else:
            sCommand='text2wave'
            # text2wave is an executable festival script
            s1=sCommand+' "'+sFILEPATH+'" -o "'+sTMP1+'"' 
            readtexttools.myossystem(s1)
            readtexttools.ProcessWaveMedia(sC,sTMP1,sIMG1,sOUT1,sAUDIBLE,sVISIBLE)
    except IOError,err:
        print ('I was unable to read!')
        print (str(err))
        usage()
        sys.exit(2)
Beispiel #6
0
def picoread(sTXT,sLANG,sVISIBLE,sAUDIBLE,sTMP0,sIMG1,sB):
  '''
  sTXT - Text to speak
  sLANG - Supported two or four letter language code - defaults to US English
  sVISIBLE- Use a graphical media player,or False for a command line media player
  sTMP0 - Name of desired output file
  sAUDIBLE - If false, then don't play the sound file
  sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
  '''
  sOUT1=""
  if sLANG[:2].lower()=="de":
    s="de-DE"
  elif sLANG[:2].lower()=="en":
    if sLANG[-2:].upper() in "AU;BD;BS;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT":
      s="en-GB"
    else:
      s="en-US"
  elif sLANG[:2].lower()=="es":
    s="es-ES"
  elif sLANG[:2].lower()=="fr":
    s="fr-FR"
  elif sLANG[:2].lower()=="it":
    s="it-IT"
  else:
    s="en-US"
  # Determine the output file name
  sOUT1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"OUT")
  # Determine the temporary file name
  sTMP1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"TEMP")

  # Some apps throw an error if we try to overwrite a file, so delete old versions
  if os.path.isfile(sTMP1):
    os.remove(sTMP1)
  if os.path.isfile(sOUT1):
    os.remove(sOUT1)
  try:
    if "windows" in platform.system().lower():
      sCommand=readtexttools.getWinFullPath("opt/picosh.exe")
      if "de" in s.lower():
        s1=sCommand+ ' –v de-DE_gl0 "' + sTXT+'" "'  + sTMP1 + '"'
      else: # Pico for Windows defaults to British English
        s1=sCommand+ ' "' + sTXT+'" "'  + sTMP1 + '"'
    else:
      sCommand='pico2wave'
      s1=sCommand+' -l '+s+' -w "'+sTMP1+'" '+sTXT 
    readtexttools.myossystem(s1)
    readtexttools.ProcessWaveMedia(sB,sTMP1,sIMG1,sOUT1,sAUDIBLE,sVISIBLE)
  except IOError,err:
    print 'I was unable to read!'
    print str(err)
    usage()
    sys.exit(2)
def picoread(sTXT,sLANG,sVISIBLE,sAUDIBLE,sTMP0,sIMG1,sB):
    '''
        sTXT - Text to speak
        sLANG - Supported two or four letter language code - defaults to US English
        sVISIBLE- Use a graphical media player,or False for a command line media player
        sTMP0 - Name of desired output file
        sAUDIBLE - If false, then don't play the sound file
        sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
        '''
    sOUT1=""
    if sLANG[:2].lower()=="de":
        s="de-DE"
    elif sLANG[:2].lower()=="en":
        if sLANG[-2:].upper() in "AU;BD;BS;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT":
            s="en-GB"
        else:
            s="en-US"
    elif sLANG[:2].lower()=="es":
        s="es-ES"
    elif sLANG[:2].lower()=="fr":
        s="fr-FR"
    elif sLANG[:2].lower()=="it":
        s="it-IT"
    else:
        s="en-US"
    # Determine the output file name
    sOUT1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"OUT")
    # Determine the temporary file name
    sTMP1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"TEMP")
    
    # Some apps throw an error if we try to overwrite a file, so delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if "windows" in platform.system().lower():
            sCommand=readtexttools.getWinFullPath("opt/picosh.exe")
            if "de" in s.lower():
                s1=sCommand+ ' –v de-DE_gl0 "' + sTXT+'" "'  + sTMP1 + '"'
            else: # Pico for Windows defaults to British English
                s1=sCommand+ ' "' + sTXT+'" "'  + sTMP1 + '"'
        else:
            sCommand='pico2wave'
            s1=sCommand+' -l '+s+' -w "'+sTMP1+'" '+sTXT 
        readtexttools.myossystem(s1)
        readtexttools.ProcessWaveMedia(sB,sTMP1,sIMG1,sOUT1,sAUDIBLE,sVISIBLE)
    except IOError,err:
        print ('I was unable to read!')
        print (str(err))
        usage()
        sys.exit(2)
Beispiel #8
0
def espkread(sTXT, sLANG, sVISIBLE, sAUDIBLE, sTMP0, sIMG1, sB):
    '''
  sTXT - Text to speak
  sLANG - Supported two or four letter language code - defaults to US English
  sVISIBLE- Use a graphical media player,or False for a command line media player
  sTMP1 - Name of desired output file
  sAUDIBLE - If false, then don't play the sound file
  sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
  '''
    sOUT1 = ""
    if sLANG[:2].lower() == "de":
        s = "de"
    elif sLANG[:2].lower() == "en":
        if sLANG[-2:].upper() in "AU;BD;BS;CA;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT":
            s = "en"
        else:
            s = "en-us"
    elif sLANG[:2].lower() == "es":
        if sLANG[-2:].upper() in "ES":
            s = "es"
        elif sLANG[-2:].upper() in "MX":
            s = "es-mx"
        else:
            s = "es-la"
    elif sLANG[:2].lower() == "nb":
        # *Office uses language code for Norwegian Bokmal - nb
        #  NO is the country code for Norway, not an official language code.
        s = "no"
    elif sLANG[:2].lower() == "pt":
        if sLANG[-2:].upper() in "PT":
            s = "pt-pt"
        else:
            s = "pt"
    elif sLANG[:2].lower() == "zh":
        if sLANG[-2:].upper() in "HK;MO":
            # Yue is official language in Hong Kong & Macau
            s = "zh-yue"
        else:
            s = "zh"
    elif sLANG[:2].lower(
    ) in "af;bs;ca;cs;cy;da;de;el;eo;fi;fr;hi;hr;hu;hy;id;is;it;ku;la;lv;mk;nl;pl;ro;ru;sk;sq;sr;sv;sw;ta;tr;vi":
        s = sLANG[:2].lower()
    else:
        s = "en"


# Check if an mbrola voice is available for the language, otherwise use the default espeak voice
# If there are several compatible mbrola voices, this python script will choose the first one.
# For example: de2 instead of de7
    ambrola = [
        'af1', 'br1', 'br3', 'br4', 'cr1', 'cz2', 'de2', 'de4', 'de5', 'de6',
        'de7', 'en1', 'es1', 'es2', 'fr1', 'fr4', 'gr2', 'hu1', 'id1', 'it3',
        'it4', 'la1', 'nl2', 'pl1', 'pt1', 'ro1', 'sw1', 'sw2', 'tr1', 'tr2',
        'us1', 'us2', 'us3'
    ]
    aespeak = [
        'af', 'pt', 'pt', 'pt', 'hr', 'cs', 'de', 'de', 'de', 'de', 'de', 'en',
        'es', 'es', 'fr', 'fr', 'el', 'hu', 'id', 'it', 'it', 'la', 'nl', 'pl',
        'pt-pt', 'ro', 'sv', 'sv', 'tr', 'tr', 'en-us', 'en-us', 'en-us'
    ]
    sVoice = s  # default to standard espeak voice
    for i in range(len(aespeak)):
        # Check voice
        if aespeak[i] == s:
            if "windows" in platform.system().lower():
                if os.path.isfile(
                        os.path.join(os.getenv("ProgramFiles"),
                                     "eSpeak/espeak-data/mbrola", ambrola[i])):
                    sVoice = "mb-" + ambrola[i]
                    break
                elif os.getenv("ProgramFiles(x86)"):
                    if os.path.isfile(
                            os.path.join(os.getenv("ProgramFiles(x86)"),
                                         "eSpeak/espeak-data/mbrola",
                                         ambrola[i])):
                        sVoice = "mb-" + ambrola[i]
                        break
            else:
                if os.path.isfile(
                        os.path.join("/usr/share/mbrola/voices",
                                     ambrola[i])) or os.path.isfile(
                                         os.path.join("/usr/share/mbrola/",
                                                      ambrola[i], ambrola[i])):
                    sVoice = "mb-" + ambrola[i]
                    break
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "OUT")
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "TEMP")

    # Some apps throw an error if we try to overwrite a file, so delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        # espeak must be in your system's path
        # for example: /usr/bin/ or /usr/local/bin/
        sCommand = "espeak"
        if "windows" in platform.system().lower():
            sCommand = readtexttools.getWinFullPath(
                "eSpeak/command_line/espeak.exe")
        s1 = '"' + sCommand + '" -v ' + sVoice + ' -w "' + sTMP1 + '" ' + sTXT
        readtexttools.myossystem(s1)
        readtexttools.ProcessWaveMedia(sB, sTMP1, sIMG1, sOUT1, sAUDIBLE,
                                       sVISIBLE)
    except (IOError):
        print('I was unable to use espeak and read text tools!')
        usage()
def espkread(sTXT,sLANG,sVISIBLE,sAUDIBLE,sTMP0,sIMG1,sB):
  '''
  sTXT - Text to speak
  sLANG - Supported two or four letter language code - defaults to US English
  sVISIBLE- Use a graphical media player,or False for a command line media player
  sTMP1 - Name of desired output file
  sAUDIBLE - If false, then don't play the sound file
  sIMG1 - a .png or .jpg file is required if we are making a movie, otherwise it is ignored.
  '''
  sOUT1=""
  if sLANG[:2].lower()=="de":
    s="de"
  elif sLANG[:2].lower()=="en":
    if sLANG[-2:].upper() in "AU;BD;BS;CA;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT":
      s="en"
    else:
      s="en-us"
  elif sLANG[:2].lower()=="es":
    if sLANG[-2:].upper() in "ES":
      s="es"
    elif sLANG[-2:].upper() in "MX":
      s="es-mx"
    else:
      s="es-la"
  elif sLANG[:2].lower()=="nb": 
    # *Office uses language code for Norwegian Bokmal - nb
    #  NO is the country code for Norway, not an official language code.
    s="no"
  elif sLANG[:2].lower()=="pt":
    if sLANG[-2:].upper() in "PT":
      s="pt-pt"
    else:
      s="pt"
  elif sLANG[:2].lower()=="zh":
    if sLANG[-2:].upper() in "HK;MO":
      # Yue is official language in Hong Kong & Macau
      s="zh-yue"
    else:
      s="zh"
  elif sLANG[:2].lower() in "af;bs;ca;cs;cy;da;de;el;eo;fi;fr;hi;hr;hu;hy;id;is;it;ku;la;lv;mk;nl;pl;ro;ru;sk;sq;sr;sv;sw;ta;tr;vi":
    s=sLANG[:2].lower()
  else:
    s="en"
# Check if an mbrola voice is available for the language, otherwise use the default espeak voice 
# If there are several compatible mbrola voices, this python script will choose the first one. 
# For example: de2 instead of de7
  ambrola = [ 'af1', 'br1', 'br3', 'br4', 'cr1', 'cz2', 'de2', 'de4', 'de5', 'de6', 'de7', 'en1', 'es1', 'es2', 'fr1', 'fr4', 'gr2', 'hu1', 'id1', 'it3', 'it4', 'la1', 'nl2', 'pl1', 'pt1', 'ro1', 'sw1', 'sw2', 'tr1', 'tr2', 'us1', 'us2', 'us3' ]
  aespeak = [ 'af', 'pt', 'pt', 'pt', 'hr', 'cs', 'de', 'de', 'de', 'de', 'de', 'en', 'es', 'es', 'fr', 'fr', 'el', 'hu', 'id', 'it', 'it', 'la', 'nl', 'pl', 'pt-pt', 'ro', 'sv', 'sv', 'tr', 'tr', 'en-us', 'en-us', 'en-us' ]
  sVoice=s # default to standard espeak voice
  for i in range(len(aespeak)):
    # Check voice
    if aespeak[i] == s:
      if "windows" in platform.system().lower():
        if os.path.isfile(os.path.join(os.getenv("ProgramFiles"),"eSpeak/espeak-data/mbrola",ambrola[i])):
          sVoice="mb-"+ambrola[i]
          break
        elif os.getenv("ProgramFiles(x86)"):
          if os.path.isfile(os.path.join(os.getenv("ProgramFiles(x86)"),"eSpeak/espeak-data/mbrola",ambrola[i])):
            sVoice="mb-"+ambrola[i]
            break 
      else:
        if os.path.isfile(os.path.join("/usr/share/mbrola/voices",ambrola[i])) or os.path.isfile(os.path.join("/usr/share/mbrola/",ambrola[i],ambrola[i])):
          sVoice="mb-"+ambrola[i]
          break
  # Determine the output file name
  sOUT1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"OUT")
  # Determine the temporary file name
  sTMP1=readtexttools.fsGetSoundFileName(sTMP0,sIMG1,"TEMP")

  # Some apps throw an error if we try to overwrite a file, so delete old versions
  if os.path.isfile(sTMP1):
    os.remove(sTMP1)
  if os.path.isfile(sOUT1):
    os.remove(sOUT1)
  try:
    # espeak must be in your system's path 
    # for example: /usr/bin/ or /usr/local/bin/
    sCommand="espeak"
    if "windows" in platform.system().lower():
      sCommand=readtexttools.getWinFullPath("eSpeak/command_line/espeak.exe")
    s1='"'+sCommand+'" -v '+sVoice+' -w "'+sTMP1+'" '+sTXT
    readtexttools.myossystem(s1)
    readtexttools.ProcessWaveMedia(sB,sTMP1,sIMG1,sOUT1,sAUDIBLE,sVISIBLE)
  except (IOError):
    print ('I was unable to use espeak and read text tools!')
    usage()
def espkread(sTXTFILE,
             sLANG,
             sVISIBLE,
             sAUDIBLE,
             sTMP0,
             sIMG1,
             sB,
             sPOSTPROCESS,
             sART,
             sDIM,
             iPITCH,
             iRATE):
    '''
Creates a temporary speech-synthesis sound file and optionally
reads the file aloud.

+ `sTXTFILE` - Name of text file to speak
+ `sLANG` - Supported two or four letter language code - defaults to US English
+ `sVISIBLE` - Use a graphic media player, or False for invisible player
+ `sTMP0` - Name of desired output media file
+ `sAUDIBLE` - If false, then don't play the sound file
+ `sIMG1` - a .png or .jpg file if required.
+ `sB` - Commentary or title for post processing
+ `sPOSTPROCESS` - Get information, play file, or convert a file
+ `sART` - Artist or Author
+ `sDIM` - Dimensions to scale photo '600x600'
+ `iPITCH` - pitch value from 5 to 100, default 50
+ `iRATE` - rate value from 20 to 640, default 160
    '''
    sOUT1 = ''

    if sLANG[:2].lower() in ['de']:
        s = 'de'
    elif sLANG[:2].lower() in ['en']:
        if sLANG[-2:].upper() in [
                'AU', 
                'BD', 
                'BS', 
                'CA', 
                'GB', 
                'GH', 
                'HK', 
                'IE', 
                'IN', 
                'JM', 
                'NZ', 
                'PK', 
                'SA', 
                'TT']:
            s = 'en'
        else:
            s = 'en-us'
    elif sLANG[:2].lower() in ['es']:
        if sLANG[-2:].upper() in ['ES']:
            s = 'es'
        elif sLANG[-2:].upper() in ['MX']:
            s = 'es-mx'
        else:
            s = 'es-la'
    elif sLANG[:2].lower() in ['nb']:
        # *Office uses language code for Norwegian Bokmal - nb
        #  NO is the country code for Norway, not an official language code.
        s = 'no'
    elif sLANG[:2].lower() in ['pt']:
        if sLANG[-2:].upper() in ['PT']:
            s = 'pt-pt'
        else:
            s = 'pt'
    elif sLANG[:2].lower() in ['zh']:
        if sLANG[-2:].upper() in ['HK','MO']:
            # Yue is official language in Hong Kong & Macau
            s = 'zh-yue'
        else:
            s = 'zh'
    elif sLANG[:2].lower() in [
            'af', 
            'bs', 
            'ca', 
            'cs', 
            'cy', 
            'da', 
            'de', 
            'el', 
            'eo', 
            'fi', 
            'fr', 
            'hi', 
            'hr', 
            'hu', 
            'hy', 
            'id', 
            'is', 
            'it', 
            'ku', 
            'la', 
            'lv', 
            'mk', 
            'nl', 
            'pl', 
            'ro', 
            'ru', 
            'sk', 
            'sq', 
            'sr', 
            'sv', 
            'sw', 
            'ta', 
            'tr', 
            'vi']:
        s = sLANG[:2].lower()
    else:
        s = 'en'
    sVoice = s  # standard espeak voice
    if sPOSTPROCESS == 'ProcessWaveMedia':
        # Check if an mbrola voice is available for the language, otherwise use
        # the default espeak voice.  If there are several compatible mbrola
        # voices, this python script will choose the first one - for example:
        # de2 instead of de7.
        #
        # Dictionary : `a2` is the locally installed language abbreviation;
        # `a1` is the equivalent ISO 639-1 standard for languages, except in
        # the cases of pt-PT and en-US, which include a regional ISO code.
        a0 = [
            {'a2': 'af1', 'a1': 'af'},
            {'a2': 'br1', 'a1': 'pt'},
            {'a2': 'br3', 'a1': 'pt'},
            {'a2': 'br4', 'a1': 'pt'},
            {'a2': 'cr1', 'a1': 'hr'},
            {'a2': 'cz2', 'a1': 'cs'},
            {'a2': 'de2', 'a1': 'de'},
            {'a2': 'de4', 'a1': 'de'},
            {'a2': 'de5', 'a1': 'de'},
            {'a2': 'de6', 'a1': 'de'},
            {'a2': 'de7', 'a1': 'de'},
            {'a2': 'en1', 'a1': 'en'},
            {'a2': 'es1', 'a1': 'es'},
            {'a2': 'es2', 'a1': 'es'},
            {'a2': 'fr1', 'a1': 'fr'},
            {'a2': 'fr4', 'a1': 'fr'},
            {'a2': 'gr2', 'a1': 'el'},
            {'a2': 'hu1', 'a1': 'hu'},
            {'a2': 'id1', 'a1': 'id'},
            {'a2': 'it3', 'a1': 'it'},
            {'a2': 'it4', 'a1': 'it'},
            {'a2': 'la2', 'a1': 'la'},
            {'a2': 'nl2', 'a1': 'nl'},
            {'a2': 'pl1', 'a1': 'pl'},
            {'a2': 'pt1', 'a1': 'pt-pt'},
            {'a2': 'ro1', 'a1': 'ro'},
            {'a2': 'sw1', 'a1': 'sv'},
            {'a2': 'sw2', 'a1': 'sv'},
            {'a2': 'tr1', 'a1': 'tr'},
            {'a2': 'tr2', 'a1': 'tr'},
            {'a2': 'us1', 'a1': 'en-us'},
            {'a2': 'us2', 'a1': 'en-us'},
            {'a2': 'us3', 'a1': 'en-us'},
            {'a2': 'en1', 'a1': 'en-us'}]

        for i in range(len(a0)):
            # Identify an mbrola voice if it is installed
            
            if a0[i]['a1'] == s:
                if 'nt' in os.name.lower():
                    if os.path.isfile(os.path.join(os.getenv('ProgramFiles'),
                                                   'eSpeak/espeak-data/mbrola',
                                                   a0[i]['a2'])):
                        sVoice = 'mb-' + a0[i]['a2']
                        break
                    elif os.getenv('ProgramFiles(x86)'):
                        sPFX86 = os.getenv('ProgramFiles(x86)')
                        sEEDM = 'eSpeak/espeak-data/mbrola'
                        if (
                           os.path.isfile(os.path.join(sPFX86,
                                                       sEEDM,
                                                       a0[i]['a2']))):
                            sVoice = 'mb-' + a0[i]['a2']
                            break
                else:
                    print(os.path.join('/usr/share/mbrola/voices',
                                                   a0[i]['a2']))
                    if os.path.isfile(os.path.join('/usr/share/mbrola/voices',
                                                   a0[i]['a2'])):
                        sVoice = 'mb-' + a0[i]['a2']
                        break
                    elif os.path.isfile(os.path.join('/usr/share/mbrola/',
                                                     a0[i]['a2'],
                                                     a0[i]['a2'])):
                        sVoice = 'mb-' + a0[i]['a2']
                        break
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'OUT')
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'TEMP')

    # Remove old files.
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        # espeak must be in your system's path
        # for example: /usr/bin/ or /usr/local/bin/
        sApp = 'espeak'
        sSub = 'eSpeak/command_line/espeak.exe'
        if 'nt' in os.name.lower():
            sApp = readtexttools.getWinFullPath(sSub)
        s1 = ''.join([
                '"',
                sApp,
                '" -b 1 -p ',
                str(iPITCH),
                ' -s ',
                str(iRATE),
                ' -v ',
                sVoice,
                ' -w "',
                sTMP1,
                '" -f "',
                sTXTFILE,
                '"'])
        readtexttools.myossystem(s1)
        print ("-----------------------------------------------------")
        print (s1)
        if sPOSTPROCESS == "ProcessWaveMedia":
            print ("ProcessWaveMedia")
            readtexttools.ProcessWaveMedia(sB,
                                           sTMP1,
                                           sIMG1,
                                           sOUT1,
                                           sAUDIBLE,
                                           sVISIBLE,
                                           sART,
                                           sDIM
                                           )
        elif sPOSTPROCESS == "ShowWavtoSeconds":
            print ("ShowWavtoSeconds")
            print (readtexttools.WavtoSeconds(sTMP1))
            print ("-----------------------------------------------------")
    except (IOError):
        print ('I was unable to use espeak and read text tools!')
        usage()
def espkread(sTXTFILE,
             sLANG,
             sVISIBLE,
             sAUDIBLE,
             sTMP0,
             sIMG1,
             sB,
             sPOSTPROCESS,
             sART,
             sDIM,
             iPITCH,
             iRATE):
    '''
    sTXTFILE - Name of text file to speak
    sLANG - Supported two or four letter language code - defaults to US English
    sVISIBLE- Use a graphic media player, or False for invisible player
    sTMP0 - Name of desired output media file
    sAUDIBLE - If false, then don't play the sound file
    sIMG1 - a .png or .jpg file if required.
    sB - Commentary or title for post processing
    sPOSTPROCESS - Get information, play file, or convert a file
    sART - Artist or Author
    sDIM - Dimensions to scale photo '600x600'
    iPITCH - pitch value from 5 to 100, default 50
    iRATE - rate value from 20 to 640, default 160
    '''
    sOUT1 = ''
    sOTHER = 'af;bs;ca;cs;cy;da;de;el;eo;fi;fr;hi;hr;hu;hy;id;is;it;ku;la;lv;'
    sOTHER = sOTHER + 'mk;nl;pl;ro;ru;sk;sq;sr;sv;sw;ta;tr;vi'

    if sLANG[:2].lower() == 'de':
        s = 'de'
    elif sLANG[:2].lower() == 'en':
        if sLANG[-2:].upper() in 'AU;BD;BS;CA;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT':
            s = 'en'
        else:
            s = 'en-us'
    elif sLANG[:2].lower() == 'es':
        if sLANG[-2:].upper() in 'ES':
            s = 'es'
        elif sLANG[-2:].upper() in 'MX':
            s = 'es-mx'
        else:
            s = 'es-la'
    elif sLANG[:2].lower() == 'nb':
        # *Office uses language code for Norwegian Bokmal - nb
        #  NO is the country code for Norway, not an official language code.
        s = 'no'
    elif sLANG[:2].lower() == 'pt':
        if sLANG[-2:].upper() in 'PT':
            s = 'pt-pt'
        else:
            s = 'pt'
    elif sLANG[:2].lower() == 'zh':
        if sLANG[-2:].upper() in 'HK;MO':
            # Yue is official language in Hong Kong & Macau
            s = 'zh-yue'
        else:
            s = 'zh'
    elif sLANG[:2].lower() in sOTHER:
        s = sLANG[:2].lower()
    else:
        s = 'en'
    sVoice = s  # standard espeak voice
    if sPOSTPROCESS == 'ProcessWaveMedia':
        # Check if an mbrola voice is available for the language, otherwise use
        # the default espeak voice.  If there are several compatible mbrola
        # voices, this python script will choose the first one - for example:
        # de2 instead of de7
        ambrola = ['af1',
                   'br1',
                   'br3',
                   'br4',
                   'cr1',
                   'cz2',
                   'de2',
                   'de4',
                   'de5',
                   'de6',
                   'de7',
                   'en1',
                   'es1',
                   'es2',
                   'fr1',
                   'fr4',
                   'gr2',
                   'hu1',
                   'id1',
                   'it3',
                   'it4',
                   'la1',
                   'nl2',
                   'pl1',
                   'pt1',
                   'ro1',
                   'sw1',
                   'sw2',
                   'tr1',
                   'tr2',
                   'us1',
                   'us2',
                   'us3']
        aespeak = ['af',
                   'pt',
                   'pt',
                   'pt',
                   'hr',
                   'cs',
                   'de',
                   'de',
                   'de',
                   'de',
                   'de',
                   'en',
                   'es',
                   'es',
                   'fr',
                   'fr',
                   'el',
                   'hu',
                   'id',
                   'it',
                   'it',
                   'la',
                   'nl',
                   'pl',
                   'pt-pt',
                   'ro',
                   'sv',
                   'sv',
                   'tr',
                   'tr',
                   'en-us',
                   'en-us',
                   'en-us']
        for i in range(len(aespeak)):
            # Identify an mbrola voice if it is installed
            if aespeak[i] == s:
                if 'windows' in platform.system().lower():
                    if os.path.isfile(os.path.join(os.getenv('ProgramFiles'),
                                                   'eSpeak/espeak-data/mbrola',
                                                   ambrola[i])):
                        sVoice = 'mb-' + ambrola[i]
                        break
                    elif os.getenv('ProgramFiles(x86)'):
                        sPFX86 = os.getenv('ProgramFiles(x86)')
                        sEEDM = 'eSpeak/espeak-data/mbrola'
                        if (
                           os.path.isfile(os.path.join(sPFX86,
                                                       sEEDM,
                                                       ambrola[i]))):
                            sVoice = 'mb-' + ambrola[i]
                            break
                else:
                    if os.path.isfile(os.path.join('/usr/share/mbrola/voices',
                                                   ambrola[i])):
                        sVoice = 'mb-' + ambrola[i]
                        break
                    elif os.path.isfile(os.path.join('/usr/share/mbrola/',
                                                     ambrola[i],
                                                     ambrola[i])):
                        sVoice = 'mb-' + ambrola[i]
                        break
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'OUT')
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'TEMP')

    # Remove old files.
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        # espeak must be in your system's path
        # for example: /usr/bin/ or /usr/local/bin/
        sApp = 'espeak'
        sSub = 'eSpeak/command_line/espeak.exe'
        if 'windows' in platform.system().lower():
            sApp = readtexttools.getWinFullPath(sSub)
        s1 = '"' + sApp + '" -b 1 -p ' + str(iPITCH) + ' -s ' + str(iRATE)
        s1 = s1 + ' -v ' + sVoice + ' -w "' + sTMP1
        s1 = s1 + '" -f "' + sTXTFILE + '"'
        readtexttools.myossystem(s1)
        print ("-----------------------------------------------------")
        print (s1)
        if sPOSTPROCESS == "ProcessWaveMedia":
            print ("ProcessWaveMedia")
            readtexttools.ProcessWaveMedia(sB,
                                           sTMP1,
                                           sIMG1,
                                           sOUT1,
                                           sAUDIBLE,
                                           sVISIBLE,
                                           sART,
                                           sDIM
                                           )
        elif sPOSTPROCESS == "ShowWavtoSeconds":
            print ("ShowWavtoSeconds")
            print (readtexttools.WavtoSeconds(sTMP1))
            print ("-----------------------------------------------------")
    except (IOError):
        print ('I was unable to use espeak and read text tools!')
        usage()
def festivalread(sFILEPATH,
                 sVISIBLE,
                 sAUDIBLE,
                 sTMP0,
                 sIMG1,
                 sC,
                 sEVAL1,
                 sB,
                 sART,
                 sDIM):
    '''
Creates a temporary speech-synthesis sound file and optionally
reads the file aloud.

+ `sTXTFILE` - Text File to speak
+ `sVISIBLE`- Use a graphic media player, or False for invisible player
+ `sTMP0` - Name of desired output file
+ `sAUDIBLE` - If false, then don't play the sound file
+ `sIMG1` - a .png or .jpg file if required.
+ `sC` - text
+ `sEVAL1` - Linux text2wave command prefix, like `(voice_upc_ca_ona_hts)`
+ `sB` - title
+ `sART` - artist or author
+ `sDIM` - Dimensions to scale photo '600x600'
    '''
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "OUT")
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, "TEMP")

    # Delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if 'nt' in os.name.lower():
            if readtexttools.getWinFullPath('festival/text2wave'):
                sBasApp = readtexttools.getWinFullPath('festival/festival.exe')
                sBasScr = readtexttools.getWinFullPath('festival/text2wave')
                sApp = sBasApp + ' --script "' + sBasScr + '"'
                s1 = sApp + ' "' + sFILEPATH + '" -o "' + sTMP1 + '"'
                readtexttools.myossystem(s1)
                readtexttools.ProcessWaveMedia(sB,
                                               sTMP1,
                                               sIMG1,
                                               sOUT1,
                                               sAUDIBLE,
                                               sVISIBLE,
                                               sART,
                                               sDIM)
            else:
                # With Windows, this script only supports reading text aloud.
                sApp = readtexttools.getWinFullPath('festival/festival.exe')
                s1 = sApp + '--tts  "' + sFILEPATH + '"'
            readtexttools.myossystem(s1)
        else:
            sApp = 'text2wave'
            # text2wave is an executable festival script
            if len(sEVAL1) == 0:
                s1 = ''.join([
                        sApp, ' "',
                        sFILEPATH,
                        '" -o "',
                        sTMP1,
                        '"'])
            else:
                s1 = ''.join([
                        sApp,
                        ' -eval "',
                        sEVAL1,
                        '" "',
                        sFILEPATH,
                        '" -o "',
                        sTMP1,
                        '"'])
            readtexttools.myossystem(s1)
            readtexttools.ProcessWaveMedia(sB,
                                           sTMP1,
                                           sIMG1,
                                           sOUT1,
                                           sAUDIBLE,
                                           sVISIBLE,
                                           sART,
                                           sDIM)
    except IOError as err:
        print ('I was unable to read!')
        usage()
        sys.exit(2)
def picoread(sTXT, sLANG, sVISIBLE, sAUDIBLE, sTMP0, sIMG1, sB, sART, sDIM):
    '''
    sTXT - Actual text to speak. The file must be written as utf-8.
    sLANG - Supported two or four letter language code - defaults to US English
    sVISIBLE- Use a graphic media player, or False for invisible player
    sTMP0 - Name of desired output media file
    sAUDIBLE - If false, then don't play the sound file
    sIMG1 - a .png or .jpg file if required.
    sB - Commentary or title for post processing
    sPOSTPROCESS - Get information, play file, or convert a file
    sART - Artist or Author
    sDIM - Dimensions to scale photo '600x600'
    '''
    sOUT1 = ''
    if sLANG[:2].lower() == 'de':
        s = 'de-DE'
    elif sLANG[:2].lower() == 'en':
        if sLANG[-2:].upper() in 'AU;BD;BS;GB;GH;HK;IE;IN;JM;NZ;PK;SA;TT':
            s = 'en-GB'
        else:
            s = 'en-US'
    elif sLANG[:2].lower() == 'es':
        s = 'es-ES'
    elif sLANG[:2].lower() == 'fr':
        s = 'fr-FR'
    elif sLANG[:2].lower() == 'it':
        s = 'it-IT'
    else:
        s = 'en-US'
    # Determine the output file name
    sOUT1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'OUT')
    # Determine the temporary file name
    sTMP1 = readtexttools.fsGetSoundFileName(sTMP0, sIMG1, 'TEMP')

    # Delete old versions
    if os.path.isfile(sTMP1):
        os.remove(sTMP1)
    if os.path.isfile(sOUT1):
        os.remove(sOUT1)
    try:
        if 'windows' in platform.system().lower():
            sCommand = readtexttools.getWinFullPath('opt/picosh.exe')
            if "de" in s.lower():
                s1 = sCommand + ' –v de-DE_gl0 "' + sTXT + '" "' + sTMP1 + '"'
            else:  # Pico for Windows defaults to British English
                s1 = sCommand + ' "' + sTXT+'" "' + sTMP1 + '"'
        else:
            sCommand = 'pico2wave'
            s1 = sCommand + ' -l ' + s + ' -w "' + sTMP1 + '"  ' + sTXT
        readtexttools.myossystem(s1)
        readtexttools.ProcessWaveMedia(sB,
                                       sTMP1,
                                       sIMG1,
                                       sOUT1,
                                       sAUDIBLE,
                                       sVISIBLE,
                                       sART,
                                       sDIM
                                       )
    except (IOError):
        print ('I was unable to read!')
        usage()
        sys.exit(2)