sinatra-praat 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5842817d74c7c54fd3f140216371aeddd7f7db67
4
+ data.tar.gz: 99c01eda0444a33894af44bba2eaf4042ea8c40a
5
+ SHA512:
6
+ metadata.gz: 3258fdf638620d92e78c68de88633a9946f871108ed95b477943e5d3e91311ded25b683508332ae76d24074ca625707366a6f44b2ad0c24744dc352b908ea02a
7
+ data.tar.gz: 3c76fc4c1e6f8383008fd8852f1abad9a59580f8454bf67c7ebdaeeae2ec85742fda02d0a7d4e07e22120131b40af8d557eb613cfcea461f672ce84dbcbda963
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatra-praat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Max Holder
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Sinatra::Praat
2
+
3
+ A Sinatra extension for running basic Praat commands.
4
+
5
+ This is not really intended for use outside of the
6
+ [vocal_tract_length](https://github.com/mxhold/vocal_tract_length) project so it
7
+ offers very little functionality but may be useful as a reference.
8
+
9
+ # Usage
10
+
11
+ Currently, it adds a helper method `extract_formant1` and a POST route
12
+ `/extract_formant1`.
13
+
14
+ The helper method takes the same arguments as the Praat [To
15
+ Formant...](http://www.fon.hum.uva.nl/praat/manual/Sound__To_Formant__burg____.html)
16
+ command, but the route uses defaults for all the arguments except the file.
17
+
18
+ The `POST /extract_formant1` route expects a WAV file as the `data` param and returns its mean F<sub>1</sub>.
19
+
20
+ ## Installation
21
+
22
+ This assumes you have already installed [Praat](http://praat.org) and it is
23
+ available as `praat` in your $PATH.
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'sinatra-praat'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install sinatra-praat
38
+
39
+ In your Sinatra application, add the following:
40
+
41
+ ```
42
+ require 'sinatra/praat'
43
+
44
+ class MyApp < Sinatra::Base
45
+ register Sinatra::Praat
46
+ end
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/mxhold/sinatra-praat/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/test_*.rb"
6
+ end
7
+
@@ -0,0 +1,16 @@
1
+ # Usage: praat extractFormants.praat filename.wav nFormants maxFormant windowSize preEmphasis
2
+ # Example: praat extractFormants.praat test.wav 5 5500 0.025 50
3
+
4
+ form Get_arguments
5
+ word audioFile
6
+ integer nFormants
7
+ integer maxFormant
8
+ real windowSize
9
+ integer preEmphasis
10
+ endform
11
+
12
+ Read from file... 'audioFile$'
13
+
14
+ To Formant (burg)... 0.0 'nFormants' 'maxFormant' 'windowSize' 'preEmphasis'
15
+
16
+ Get mean: 1, 0, 0, "Hertz"
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Praat
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require "sinatra/praat/version"
2
+
3
+ module Sinatra
4
+ module Praat
5
+ module Helpers
6
+ def extract_formant1(file:, formant_count: 5, max_formant_hz: 5500, window_size: 0.025, pre_emphasis: 50)
7
+ `praat #{extract_formant1_script} #{file.path} #{formant_count} #{max_formant_hz} #{window_size} #{pre_emphasis}`
8
+ end
9
+
10
+ def extract_formant1_script
11
+ File.join(__dir__, 'praat', 'extractFormant1.praat')
12
+ end
13
+ end
14
+ def self.registered(app)
15
+ app.helpers Praat::Helpers
16
+
17
+ app.post '/extract_formant1' do
18
+ begin
19
+ file = params["data"][:tempfile]
20
+ extract_formant1(file: file)
21
+ rescue
22
+ status 400
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sinatra/praat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sinatra-praat"
8
+ spec.version = Sinatra::Praat::VERSION
9
+ spec.authors = ["Max Holder"]
10
+ spec.email = ["mxhold@gmail.com"]
11
+ spec.summary = %q{Sinatra extension for basic Praat operations.}
12
+ spec.homepage = "https://github.com/mxhold/sinatra-praat"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency 'sinatra'
25
+ end
@@ -0,0 +1,35 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ require 'minitest/autorun'
3
+ require 'rack/test'
4
+
5
+ require 'sinatra/base'
6
+ require 'sinatra/praat'
7
+
8
+ class MyApp < Sinatra::Base
9
+ register Sinatra::Praat
10
+ end
11
+
12
+ class TestPraat < Minitest::Test
13
+ include Rack::Test::Methods
14
+
15
+ def app
16
+ MyApp
17
+ end
18
+
19
+ def test_extract_formant1_error
20
+ post '/extract_formant1', { 'data' => '' }
21
+ assert_equal last_response.status, 400
22
+ end
23
+
24
+ def test_extract_formant1
25
+ app.send(:define_method, :`) do |actual_command|
26
+ expected_command = /praat .+praat\/extractFormant1.praat \/var[^ ]+ 5 5500 0.025 5/
27
+ unless expected_command =~ actual_command
28
+ return "Incorrect Praat command: Expected: #{expected_command}, got: #{actual_command}"
29
+ end
30
+ "1234 Hertz"
31
+ end
32
+ post '/extract_formant1', { 'data' => Rack::Test::UploadedFile.new(__FILE__) }
33
+ assert_equal last_response.body, "1234 Hertz"
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-praat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Holder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - mxhold@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/sinatra/praat.rb
96
+ - lib/sinatra/praat/extractFormant1.praat
97
+ - lib/sinatra/praat/version.rb
98
+ - sinatra-praat.gemspec
99
+ - test/test_praat.rb
100
+ homepage: https://github.com/mxhold/sinatra-praat
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Sinatra extension for basic Praat operations.
124
+ test_files:
125
+ - test/test_praat.rb