wasabi_pea 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/wasabi_pea.rb +31 -0
 - metadata +45 -0
 
    
        data/lib/wasabi_pea.rb
    ADDED
    
    | 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'uri'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'open-uri'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module TextToSpeech
         
     | 
| 
      
 6 
     | 
    
         
            +
              def to_speech(language, file_name = nil)
         
     | 
| 
      
 7 
     | 
    
         
            +
                base_url = "http://translate.google.com/translate_tts?tl=#{language}&q=#{URI.escape self}"
         
     | 
| 
      
 8 
     | 
    
         
            +
                file = File.join("tmp", (file_name || self) + ".mp3")
         
     | 
| 
      
 9 
     | 
    
         
            +
                user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"
         
     | 
| 
      
 10 
     | 
    
         
            +
                begin
         
     | 
| 
      
 11 
     | 
    
         
            +
                  content = open(base_url, "User-Agent" => user_agent).read
         
     | 
| 
      
 12 
     | 
    
         
            +
                  File.open(file, 'wb') do |f|
         
     | 
| 
      
 13 
     | 
    
         
            +
                    f.puts content
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                rescue Exception => error
         
     | 
| 
      
 16 
     | 
    
         
            +
                  $stderr.puts(" #{error.message}")
         
     | 
| 
      
 17 
     | 
    
         
            +
                  exit(1)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                io = StringIO.new(open(file, "rb") {|io| io.read })
         
     | 
| 
      
 21 
     | 
    
         
            +
                io.original_filename = "#{file_name}.mp3"
         
     | 
| 
      
 22 
     | 
    
         
            +
                io.content_type = "audio/mpeg"
         
     | 
| 
      
 23 
     | 
    
         
            +
                io
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            class String
         
     | 
| 
      
 30 
     | 
    
         
            +
              include TextToSpeech
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,45 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: wasabi_pea
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: '0.1'
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Jeremy Geros
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-10-25 00:00:00.000000000Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 14 
     | 
    
         
            +
            description: Simple text to speech
         
     | 
| 
      
 15 
     | 
    
         
            +
            email: jeremy453@gmail.com
         
     | 
| 
      
 16 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/wasabi_pea.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            homepage: https://github.com/JeremyGeros/wasabi_pea
         
     | 
| 
      
 22 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 23 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 24 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 25 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 26 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 27 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 28 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 31 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 33 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 34 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 36 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 37 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 39 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 40 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 41 
     | 
    
         
            +
            rubygems_version: 1.8.10
         
     | 
| 
      
 42 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 43 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 44 
     | 
    
         
            +
            summary: Text to speech
         
     | 
| 
      
 45 
     | 
    
         
            +
            test_files: []
         
     |