On Wed, Feb 26, 2020 at 01:07:17PM +0100, Daniel Leidert wrote:
> Hi there,
> 
> the newly accepted ruby-espeak (one of the Kali packages) fails to test
> successfully with Ruby2.7. The reason seems that CSV.parse() has a behavior
> change. It does not parse the file test/fixtures/voices.txt anymore as it did.
> It seems using 
> 
> col_sep: ' '
> 
> is now interpreted literally. So fields separated by more then one space are
> not parsed as columns in a row. To demonstrate consider this line:
> 
> > Pty Language Age/Gender VoiceName       File        Other Langs
> >  5  af             M  afrikaans         af          
> 
> With ruby2.5 it is parsed like this:
> 
> > #<CSV::Row "Pty":"5" "Language":"af" "Age/Gender":"M" 
> > "VoiceName":"afrikaans"
> > "File":"af" "Other":nil "Langs":nil>
> 
> and with ruby2.7 like this:
> 
> > #<CSV::Row "Pty":nil "Language":"5" "Age/Gender":nil "VoiceName":"af" 
> > nil:nil
> > nil:nil nil:nil nil:nil nil:nil nil:nil "File":nil nil:nil nil:nil nil:nil
> > nil:nil nil:nil nil:"M" nil:nil "Other":"afrikaans" "Langs":nil nil:nil
> > nil:nil nil:nil nil:nil nil:nil nil:nil nil:nil nil:"af" nil:nil nil:nil
> > nil:nil nil:nil nil:nil nil:nil nil:nil nil:nil nil:nil nil:nil>
> 
> This seems intentional:
> https://github.com/ruby/csv/issues/67
> https://github.com/ruby/csv/commit/7798df60fed87251b26c1202eb251a7894b55469#diff-fd263cdff2717a557bddf1592762dba3R16
> 
> The file format is determined by the output of `espeak --voices` and cannot be
> changed.
> 
> Does anybody know, how to easily fix this, or is anybody up to add some magic
> to lib/espeak/voice.rb to deal with this?

----------------8<----------------8<----------------8<-----------------
diff --git a/lib/espeak/voice.rb b/lib/espeak/voice.rb
index feba95d..9ba2f1f 100644
--- a/lib/espeak/voice.rb
+++ b/lib/espeak/voice.rb
@@ -1,5 +1,3 @@
-require 'csv'
-
 module ESpeak
   class Voice
     attr_reader :language, :name, :gender, :file
@@ -12,7 +10,11 @@ module ESpeak
 
     def self.all
       voices = []
-      CSV.parse(espeak_voices, headers: :first_row, col_sep: ' ') do |row|
+      lines = espeak_voices.lines
+      lines.shift
+      lines.map do |line|
+        line.sub(/^\s+/, '').split(/\s+/)
+      end.each do |row|
         voices << Voice.new(language: row[1], gender: row[2], name: row[3], 
file: row[4] )
       end
       voices
----------------8<----------------8<----------------8<-----------------

Attachment: signature.asc
Description: PGP signature

Reply via email to