-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspeech-tools.rb
66 lines (56 loc) · 2.23 KB
/
speech-tools.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# typed: false
# frozen_string_literal: true
class SpeechTools < Formula
desc "C++ speech software library from the University of Edinburgh"
homepage "http://festvox.org/docs/speech_tools-2.4.0/"
url "http://festvox.org/packed/festival/2.5/speech_tools-2.5.0-release.tar.gz"
sha256 "e4fd97ed78f14464358d09f36dfe91bc1721b7c0fa6503e04364fb5847805dcc"
revision 1
bottle do
root_url "https://github.com/danielbair/homebrew-tap/releases/download/bottles"
# cellar :any_skip_relocation
# sha256 "b43389631b881f76529aa4458442b819dc5be784afbf5569f9e526ce3dc7e028" => :high_sierra
# sha256 "4d3681ee2194a92fcbad96371c499f5c2a71c59cfe8798b8092f0e57f793fca3" => :sierra
# sha256 "a0794d1d7f424833d2fe92726d26b6ebcc8dcf63b7f9700b19e1119ed7e2ca62" => :el_capitan
end
conflicts_with "align", because: "both install `align` binaries"
def install
ENV.deparallelize
system "./configure"
system "make"
# install all executable files in "main" directory
bin.install Dir["bin/*"].select { |f| File.file?(f) && File.executable?(f) }
bin.install Dir["main/*"].select { |f| File.file?(f) && File.executable?(f) }
end
test do
rate_hz = 16000
frequency_hz = 100
duration_secs = 5
basename = "sine"
txtfile = "#{basename}.txt"
wavfile = "#{basename}.wav"
ptcfile = "#{basename}.ptc"
File.open(txtfile, "w") do |f|
scale = 2 ** 15 - 1
f.puts Array.new(duration_secs * rate_hz) { |i|
(scale * Math.sin(frequency_hz * 2 * Math::PI * i / rate_hz)).to_i
}
end
# convert to wav format using ch_wave
system bin/"ch_wave", txtfile,
"-itype", "raw",
"-istype", "ascii",
"-f", rate_hz.to_s,
"-o", wavfile,
"-otype", "riff"
# pitch tracking to est format using pda
system bin/"pda", wavfile,
"-shift", (1 / frequency_hz.to_f).to_s,
"-o", ptcfile,
"-otype", "est"
# extract one frame from the middle using ch_track, capturing stdout
pitch = shell_output("#{bin}/ch_track #{ptcfile} -from #{frequency_hz * duration_secs / 2} -to #{frequency_hz * duration_secs / 2}")
# should be 100 (Hz)
assert_equal frequency_hz, pitch.to_i
end
end