36273f9d_and_d6a7a01.diff 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. diff --git a/README b/README
  2. index c540542..87bb3d8 100644
  3. --- a/README
  4. +++ b/README
  5. @@ -1,5 +1,5 @@
  6. PicoSpeaker
  7. -Written by Kyle
  8. +Orginally Written by Kyle and forked by shilber01 to work with SNIPS (snips.ai)
  9. DESCRIPTION
  10. diff --git a/pico.patch b/pico.patch
  11. new file mode 100644
  12. index 0000000..0e2680a
  13. --- /dev/null
  14. +++ b/pico.patch
  15. @@ -0,0 +1,19 @@
  16. +--- picospeaker.bak 2018-08-27 22:03:05.000000000 +0200
  17. ++++ picospeaker 2018-08-27 23:49:35.289440981 +0200
  18. +@@ -59,8 +59,16 @@
  19. + exit(0)
  20. + elif ( argv[opt] == '-l' ) or ( argv[opt] == '--language' ):
  21. + languages = ('en-US', 'en-GB', 'de-DE', 'es-ES', 'fr-FR', 'it-IT')
  22. ++ lang_map = {
  23. ++ 'en': 'en-US',
  24. ++ 'de': 'de-DE',
  25. ++ 'es': 'es-ES',
  26. ++ 'fr': 'fr-FR',
  27. ++ 'it': 'it-IT'}
  28. + if ( argv[opt+1] in languages ):
  29. + settings['language'] = argv[opt+1]
  30. ++ elif ( argv[opt+1] in lang_map.keys() ):
  31. ++ settings['language'] = lang_map[argv[opt+1]]
  32. + else:
  33. + stderr.write('Language ' + argv[opt+1] + ' is currently not available.\n')
  34. + stderr.write('Available languages are ' + ', '.join(languages[:-1]) + ' and ' + languages[-1] + '.\n')
  35. \ No newline at end of file
  36. diff --git a/picospeaker b/picospeaker
  37. index 6b49d34..b9f91c3 100755
  38. --- a/picospeaker
  39. +++ b/picospeaker
  40. @@ -14,8 +14,8 @@ from time import sleep
  41. # help and version tuples
  42. version = (
  43. - 'PicoSpeaker 0.6.2',
  44. - 'Written by Kyle',
  45. + 'PicoSpeaker 0.6.2-1',
  46. + 'Written by Kyle,forked by shilbert01',
  47. 'This program is free and unencumbered software released into the public domain.',
  48. 'See the included UNLICENSE file for details.')
  49. help = (
  50. @@ -59,8 +59,16 @@ def parse ():
  51. exit(0)
  52. elif ( argv[opt] == '-l' ) or ( argv[opt] == '--language' ):
  53. languages = ('en-US', 'en-GB', 'de-DE', 'es-ES', 'fr-FR', 'it-IT')
  54. + lang_map = {
  55. + 'en': 'en-US',
  56. + 'de': 'de-DE',
  57. + 'es': 'es-ES',
  58. + 'fr': 'fr-FR',
  59. + 'it': 'it-IT'}
  60. if ( argv[opt+1] in languages ):
  61. settings['language'] = argv[opt+1]
  62. + elif ( argv[opt+1] in lang_map.keys() ):
  63. + settings['language'] = lang_map[argv[opt+1]]
  64. else:
  65. stderr.write('Language ' + argv[opt+1] + ' is currently not available.\n')
  66. stderr.write('Available languages are ' + ', '.join(languages[:-1]) + ' and ' + languages[-1] + '.\n')
  67. @@ -117,7 +125,7 @@ def parse ():
  68. continue
  69. else:
  70. # First, die with an error if compression and/or type are set but no output file is specified
  71. - if ( ( settings.has_key('compression') ) or ( settings.has_key('filetype') ) ) and not ( settings.has_key('output') ):
  72. + if ( ( 'compression' in settings ) or ( 'filetype' in settings ) ) and ( 'output' not in settings ):
  73. stderr.write('You must specify the output file.\n')
  74. exit(1)
  75. # Now the text can be added to the settings object and the loop can be broken
  76. @@ -128,7 +136,7 @@ def parse ():
  77. def tts():
  78. 'convert text to speech data and store it in a temporary file using the pico2wave utility from SVox Pico'
  79. command = ['pico2wave', '-w', temp]
  80. - if ( settings.has_key('language') ): command += ['-l', settings['language']]
  81. + if ( 'language' in settings ): command += ['-l', settings['language']]
  82. command += ['--', settings['text']]
  83. try:
  84. call(command)
  85. @@ -139,16 +147,16 @@ def tts():
  86. def speaker():
  87. 'speaks the text, or saves it if an output file was specified on the command line'
  88. command = ['play', '-q']
  89. - if ( settings.has_key('volume') ): command += ['-v', settings['volume']]
  90. + if ( 'volume' in settings ): command += ['-v', settings['volume']]
  91. command.append(temp)
  92. - if ( settings.has_key('output') ):
  93. + if ( 'output' in settings ):
  94. command[0] = 'sox'
  95. del command[1]
  96. - if ( settings.has_key('filetype') ): command += ['-t', settings['filetype']]
  97. - if ( settings.has_key('compression') ): command += ['-C', settings['compression']]
  98. + if ( 'filetype' in settings ): command += ['-t', settings['filetype']]
  99. + if ( 'compression' in settings ): command += ['-C', settings['compression']]
  100. command.append(settings['output'])
  101. - if ( settings.has_key('pitch') ): command += ['gain', '-0.15', 'pitch', str(float(settings['pitch'])*100)]
  102. - if ( settings.has_key('rate') ): command += ['gain', '-0.1', 'tempo', '-s', str(1+float(settings['rate'])/100)]
  103. + if ( 'pitch' in settings ): command += ['gain', '-0.15', 'pitch', str(float(settings['pitch'])*100)]
  104. + if ( 'rate' in settings ): command += ['gain', '-0.1', 'tempo', '-s', str(1+float(settings['rate'])/100)]
  105. speak = Popen(command)
  106. sleep(0.1) # the temp file should be open by now
  107. # The temp file can be removed as soon as it is opened in case PicoSpeaker is killed while speaking
  108. @@ -157,11 +165,11 @@ def speaker():
  109. try:
  110. settings = parse()
  111. - if ( not settings.has_key('text') ):
  112. + if ( 'text' not in settings ):
  113. settings['text'] = stdin.read()
  114. tts()
  115. speaker()
  116. except KeyboardInterrupt:
  117. stderr.write('Keyboard interrupt received. Cleaning up.\n')
  118. - try: remove(temp)
  119. + try: remove(temp) # The temp file may not have been removed yet
  120. except OSError: pass # The file doesn't exist and therefore doesn't need to be removed