praatrb 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.
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'praat'
3
+
4
+ class TestPraat < Minitest::Test
5
+ def test_praat_hz_to_midi
6
+ assert_equal 81.0, Praat.hz_to_midi(880.0)
7
+ assert_equal 0.0, Praat.hz_to_midi(nil)
8
+ end
9
+ end
10
+
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'praat'
3
+
4
+ class TestPraatFormant < Minitest::Test
5
+ def test_dominant_frame
6
+
7
+ end
8
+ end
@@ -0,0 +1,73 @@
1
+ require 'minitest/autorun'
2
+ require 'praat'
3
+
4
+ class TestPraatLexer < Minitest::Test
5
+ def setup
6
+ @lexer = Praat::Lexer.new
7
+ end
8
+
9
+ def test_parses_object
10
+ text = "candidate [1]:\n"
11
+ assert_equal [[:object, "candidate", 1]], @lexer.parse(text)
12
+ end
13
+
14
+ def test_parses_collection
15
+ text = "frame []:\n"
16
+ assert_equal [[:collection, "frame"]], @lexer.parse(text)
17
+ end
18
+
19
+ def test_parses_float_property
20
+ text = "frequency = 67.32"
21
+ assert_equal [[:property, "frequency", 67.32]], @lexer.parse(text)
22
+ end
23
+
24
+ def test_parses_scientific_float
25
+ text = "intensity = 8.3178501338792e-05"
26
+ assert_equal [[:property, "intensity", 8.3178501338792e-05]], @lexer.parse(text)
27
+ end
28
+
29
+ def test_parses_integer_property
30
+ text = "nCandidates = 2"
31
+ assert_equal [[:property, "nCandidates", 2]], @lexer.parse(text)
32
+ end
33
+
34
+ def test_parses_string_property
35
+ text = "fileType = \"Pitch\""
36
+ assert_equal [[:property, "fileType", "Pitch"]], @lexer.parse(text)
37
+ end
38
+
39
+ def test_parses_indents
40
+ text = " nIndents = 2"
41
+ assert_equal [[:indent, 2], [:property, "nIndents", 2]], @lexer.parse(text)
42
+ end
43
+
44
+ def test_parses_collection_with_properties
45
+ text = <<-TXT
46
+ frame []:
47
+ frame [1]:
48
+ intensity = 0
49
+ nCandidates = 1
50
+ candidate []:
51
+ candidate [1]:
52
+ frequency = 0
53
+ strength = 0.4
54
+ TXT
55
+ exp = [ [:collection, "frame"],
56
+ [:indent, 1],
57
+ [:object, "frame", 1],
58
+ [:indent, 2],
59
+ [:property, "intensity", 0],
60
+ [:indent, 2],
61
+ [:property, "nCandidates", 1],
62
+ [:indent, 2],
63
+ [:collection, "candidate"],
64
+ [:indent, 3],
65
+ [:object, "candidate", 1],
66
+ [:indent, 4],
67
+ [:property, "frequency", 0],
68
+ [:indent, 4],
69
+ [:property, "strength", 0.4] ]
70
+
71
+ assert_equal exp, @lexer.parse(text)
72
+ end
73
+ end
@@ -0,0 +1,103 @@
1
+ require 'minitest/autorun'
2
+ require 'praat'
3
+
4
+ class TestPraatParser < Minitest::Test
5
+ def setup
6
+ @parser = Praat::Parser.new
7
+ end
8
+
9
+ def test_creates_collection
10
+ input = [[:collection, "frame"]]
11
+ output = @parser.parse input
12
+
13
+ assert Object.const_defined? 'Praat::Frames', 'Praat::Frames class not defined'
14
+ assert_kind_of Praat::Frames, output.frames
15
+ assert_kind_of Praat::MetaCollection, output.frames
16
+ end
17
+
18
+ def test_creates_object
19
+ input = [[:collection, "frame"], [:object, "frame", 1]]
20
+ output = @parser.parse input
21
+
22
+ assert Object.const_defined? 'Praat::Frame', 'Praat::Frame class not defined'
23
+ assert_kind_of Praat::Frames, output.frames
24
+ assert_kind_of Praat::Frame, output.frames.first
25
+ assert_equal output.frames, output.frames.first.parent
26
+ end
27
+
28
+ def test_adds_property
29
+ input = [[:collection, "frame"], [:object, "frame", 1], [:property, "time", 0.123]]
30
+ output = @parser.parse input
31
+
32
+ assert_equal 0.123, output.frames[0].time
33
+ end
34
+
35
+ def test_walks_backward
36
+ input = [[:collection, "frame"],
37
+ [:indent, 1],
38
+ [:object, "frame", 1],
39
+ [:indent, 2],
40
+ [:property, "time", 0.123],
41
+ [:indent, 1],
42
+ [:object, "frame", 2],
43
+ [:indent, 2],
44
+ [:property, "time", 0.456]]
45
+
46
+ output = @parser.parse input
47
+
48
+ assert_equal 0.123, output.frames[0].time
49
+ assert_equal 0.456, output.frames[1].time
50
+ end
51
+
52
+ def test_walks_backward_twice
53
+ input = [[:collection, "frame"],
54
+ [:indent, 1],
55
+ [:object, "frame", 1],
56
+ [:indent, 2],
57
+ [:property, "time", 0.123],
58
+ [:indent, 2],
59
+ [:collection, "candidate"],
60
+ [:indent, 3],
61
+ [:object, "candidate", 1],
62
+ [:indent, 4],
63
+ [:property, "frequency", 440],
64
+ [:indent, 1],
65
+ [:object, "frame", 2],
66
+ [:indent, 2],
67
+ [:property, "time", 0.456]]
68
+
69
+ output = @parser.parse input
70
+
71
+ assert_equal 440.0, output.frames[0].candidates[0].frequency
72
+ assert_equal 0.456, output.frames[1].time
73
+ end
74
+
75
+ def test_evades_class
76
+ input = [[:collection, "frame"],
77
+ [:object, "frame", 1],
78
+ [:property, "class", "Pitch 2"]]
79
+
80
+ output = @parser.parse input
81
+ assert_equal "Pitch 2", output.frames[0].klass
82
+ end
83
+
84
+ def test_adds_string_property
85
+ input = [[:collection, "frame"],
86
+ [:object, "frame", 1],
87
+ [:property, "time", 0.123],
88
+ [:property, "syllable", "ah"]]
89
+
90
+ output = @parser.parse input
91
+
92
+ assert_equal 0.123, output.frames[0].time
93
+ assert_equal "ah", output.frames[0].syllable
94
+ end
95
+
96
+ def test_snake_cases_attribute
97
+ input = [[:property, "File type", "Collection"]]
98
+
99
+ output = @parser.parse input
100
+
101
+ assert_respond_to output, :file_type
102
+ end
103
+ end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'praat'
3
+
4
+ class TestPraatPitch < Minitest::Test
5
+ def setup
6
+ @pitch = Praat.parse_file 'test/fixtures/tajm.Pitch'
7
+ end
8
+
9
+ def test_parse_file
10
+ assert_equal 600, @pitch.ceiling
11
+ end
12
+
13
+ def test_find_dominant_pitch
14
+ output = Praat.find_dominant_pitch @pitch
15
+ assert_respond_to output.frames[0], :freq
16
+ assert_nil output.frames[0].freq
17
+ assert_in_delta 180.141, output.frames[1].freq
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: praatrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Smith
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: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oedipus_lex
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.13'
69
+ description: Provides a very malleable Praat file parser
70
+ email:
71
+ - andrewchristophersmith@gmail.com
72
+ executables:
73
+ - praat_lex
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - History.txt
77
+ - Manifest.txt
78
+ - README.txt
79
+ files:
80
+ - ".autotest"
81
+ - ".gemtest"
82
+ - History.txt
83
+ - Manifest.txt
84
+ - README.txt
85
+ - Rakefile
86
+ - bin/praat_lex
87
+ - lib/praat.rb
88
+ - lib/praat_formant.rb
89
+ - lib/praat_lexer.rb
90
+ - lib/praat_lexer.rex
91
+ - lib/praat_lexer.rex.rb
92
+ - lib/praat_parser.rb
93
+ - lib/praat_pitch.rb
94
+ - test/fixtures/tajm.Pitch
95
+ - test/test.Pitch
96
+ - test/test_praat.rb
97
+ - test/test_praat_formant.rb
98
+ - test/test_praat_lexer.rb
99
+ - test/test_praat_parser.rb
100
+ - test/test_praat_pitch.rb
101
+ homepage: http://www.andrewchristophersmith.com/
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options:
107
+ - "--main"
108
+ - README.txt
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Provides a very malleable Praat file parser
127
+ test_files:
128
+ - test/test_praat.rb
129
+ - test/test_praat_formant.rb
130
+ - test/test_praat_lexer.rb
131
+ - test/test_praat_parser.rb
132
+ - test/test_praat_pitch.rb