fest 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.org +7 -7
  3. data/changelog.org +4 -0
  4. data/fest.gemspec +1 -1
  5. data/lib/fest.rb +31 -50
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e89c6318a99e7da898a9ef143b647ab1f9307a8
4
- data.tar.gz: 4ed3d7bc77af637b0fe9e49b745b5eb06b969c68
3
+ metadata.gz: 007d77826bbe60048b450b36fb760c932f23a8f4
4
+ data.tar.gz: 6c6afb39d04586cd1992371d02d362e7b7c44c38
5
5
  SHA512:
6
- metadata.gz: 1d30bddfb1cbafe103922390280278676a8bd5216283eb6a2a34b5bf8ad8310067be1cc303253da43aac548b58c873aaf0eb75124790f6a66f6902fab0151f72
7
- data.tar.gz: e632d050b36f0cdf51ed2a9eecbd657f38b674213fe73c9e33db3016f489cf8521d5a9b193fa050c5e4bb8076ef570b3ac605271399110cc391b2635ac3c46f6
6
+ metadata.gz: 34697b9fe1f6d4c0be0fda8c46b28cb8f3559c8f08514796dbac142fe5d01a9b08472d221099eaa9f3cb6f7f2a74da5a0dd3a20716b85e4e3f8c05ed7f5b92df
7
+ data.tar.gz: 5ee36535af1631ac42d6c800f3c738979d662349a98aaa1146df3d4d7e7f0b19e5c2963eaa734abd1fb6e66d0a1091b0c2e4e496da05faa98e50fb81f15a5908
data/README.org CHANGED
@@ -1,7 +1,6 @@
1
1
  ** FEST
2
2
  FEST - Ruby-адаптер, использующий [[https://wiki.archlinux.org/index.php/Festival_%28%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%29][Festival]], для озвучки текста и скриптов...
3
3
  ** Установка
4
- Требуется:
5
4
  - *nix* or OS X ...
6
5
  - [[https://wiki.archlinux.org/index.php/Festival_%28%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%29][Festival]] и нужные языки...
7
6
  - [[https://wiki.archlinux.org/index.php/PulseAudio_%28%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%29][Pulseaudio]]
@@ -34,12 +33,12 @@ text = "This is an example"
34
33
  # Все параметры
35
34
  # params || default value
36
35
  params[:path] || "/tmp"
37
- params[:down_volume] || [20,60,4] #[min, max, step]
36
+ params[:down_volume] || [20,60,4] # [min, max, step]
38
37
  params[:backlight] || nil # отменить проверку подсветки
39
38
  params[:language] || "voice_msu_ru_nsh_clunits"
40
39
 
41
40
  # Склонение
42
- text = @fest.pluraform(2, ["Сообщение", "Сообщения", "Сообщений"])
41
+ text = @fest.pluraform(2, %w(Сообщение Сообщения Сообщений))
43
42
  puts text
44
43
  # => "Сообщения"
45
44
  #+end_src
@@ -47,7 +46,8 @@ puts text
47
46
  ** Кастомизация
48
47
  #+begin_src ruby
49
48
  @fest.init(params)
50
- # Узнает текущую громкость... @path, @index ...
49
+ # Узнает текущую громкость...
50
+ # @path, @index, @min_volume, @max_volume ...
51
51
 
52
52
  @fest.check_optimal_volume
53
53
  # @volume = @current_volume - @down_volume
@@ -55,7 +55,6 @@ puts text
55
55
 
56
56
  @fest.optimize_min_and_max_volume(min_volume, max_volume)
57
57
  # Проверяет громкость и ставит min или max ...
58
- # выполняет turn_down_volume
59
58
 
60
59
  @fest.check_light # (with xbacklight)
61
60
  # Проверяет яркость не равна ли нулю... если равна выходит...
@@ -68,7 +67,7 @@ puts text
68
67
  @fest.make_wav(text)
69
68
  # Создаём wav с определённым языком ... с учётом @index...
70
69
 
71
- @fest.set_volume(volume)
70
+ @fest.change_volume(volume)
72
71
  # Ставит громкость ...
73
72
 
74
73
  @fest.expect_if_aplay_now
@@ -76,11 +75,12 @@ puts text
76
75
 
77
76
  @fest.turn_down_volume
78
77
  # Получает список входящих каналов @inputs
78
+ # Понижает громкость на @down_volume ...
79
79
  # @down_volume = @current_volume / 10 * 4
80
80
  # @down_volume = @current_volume / 10 * @params[:down_volume[2]]
81
- # Понижает громкость на @down_volume ...
82
81
 
83
82
  @fest.play_wav
83
+ # выполняет turn_down_volume
84
84
  # Проигрывает wav ...
85
85
 
86
86
  @fest.return_current_volume
data/changelog.org CHANGED
@@ -1,3 +1,7 @@
1
+ ** 1.0.7 (2015-01-07 Ср)
2
+ - Фикс min и max volume ...
3
+ ** 1.0.6 (2015-01-07 Ср)
4
+ - Рефакторинг
1
5
  ** 1.0.5 (2015-01-05 Пн)
2
6
  - Фикс паузы перед проигрыванием
3
7
  ** 1.0.4 (2015-01-03 Сб)
data/fest.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "fest"
3
- s.version = "1.0.5"
3
+ s.version = "1.0.7"
4
4
  s.authors = ["Alexsey Ermolaev"]
5
5
  s.email = %q{afay.zangetsu@gmail.com}
6
6
  s.homepage = %q{https://github.com/AfsmNGhr/fest}
data/lib/fest.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # coding: utf-8
2
-
2
+ #
3
3
  class Fest
4
-
5
- def say(string, params={})
6
- init(params={})
4
+ def say(string, params = {})
5
+ init(params)
7
6
  check_light
8
7
  @index = check_say_wav
9
8
  make_wav(string)
@@ -16,87 +15,76 @@ class Fest
16
15
 
17
16
  def init(params)
18
17
  @params = params
19
- @path = @params[:path] || "/tmp"
18
+ @path = @params[:path] || '/tmp'
20
19
  @current_volume = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
21
20
  @index = `ls -r #{@path} | grep -o '[0-9]*' | sed "1 ! d"`.to_i
21
+ @min_volume = @params[:down_volume[0]] || 20
22
+ @max_volume = @params[:down_volume[1]] || 60
22
23
  end
23
24
 
24
25
  def check_optimal_volume
25
26
  if @params[:down_volume].nil?
26
27
  @down_volume = @current_volume / 10 * 4
27
28
  @volume = @current_volume - @down_volume
28
- optimize_min_and_max_volume(20, 60)
29
29
  else
30
30
  @down_volume = @current_volume / 10 * @params[:down_volume[2]]
31
31
  @volume = @current_volume - @down_volume
32
- optimize_min_and_max_volume(@params[:down_volume[0]],
33
- @params[:down_volume[1]])
34
32
  end
33
+ optimize_min_and_max_volume
35
34
  end
36
35
 
37
- def optimize_min_and_max_volume(min_volume, max_volume)
38
- if @current_volume < min_volume
39
- play_volume = min_volume
40
- elsif @current_volume > max_volume
41
- play_volume = max_volume
42
- end
43
- optimize_volume = play_volume || @current_volume
44
- set_volume(optimize_volume)
45
- turn_down_volume
36
+ def optimize_min_and_max_volume
37
+ change_volume(
38
+ if @current_volume > @max_volume
39
+ @max_volume
40
+ elsif @current_volume < @min_volume
41
+ @min_volume
42
+ else
43
+ @current_volume
44
+ end
45
+ )
46
46
  end
47
47
 
48
48
  def check_light
49
- if @params[:backlight].nil?
50
- light = `xbacklight`.to_i
51
- exit if light == 0
52
- end
49
+ exit if @params[:backlight].nil? && `xbacklight`.to_i == 0
53
50
  end
54
51
 
55
52
  def check_say_wav
56
- if @index > 0
57
- @index += 1
58
- else
59
- @index = 1
60
- end
53
+ @index > 0 ? @index += 1 : @index = 1
61
54
  end
62
55
 
63
56
  def make_wav(string)
64
- language = @params[:language] || "voice_msu_ru_nsh_clunits"
65
57
  system("echo '#{string}' | text2wave -o #{@path}/say_#{@index}.wav \
66
- -eval '(#{language})' > /dev/null 2>&1")
58
+ -eval '(#{@params[:language] || 'voice_msu_ru_nsh_clunits'})' \
59
+ > /dev/null 2>&1")
67
60
  end
68
61
 
69
- def set_volume(volume)
62
+ def change_volume(volume)
70
63
  system("amixer set Master #{volume}% > /dev/null 2>&1")
71
64
  end
72
65
 
73
66
  def expect_if_aplay_now
74
- while true
67
+ loop do
75
68
  sleep 1
76
- aplay = `ps -el | grep aplay | wc -l`.to_i
77
- break if aplay == 0
69
+ break if `ps -el | grep aplay | wc -l`.to_i == 0
78
70
  end
79
71
  end
80
72
 
81
73
  def turn_down_volume
82
74
  @inputs = `pactl list sink-inputs | grep № | grep -o '[0-9]*'`.split("\n")
83
- new_volume = @volume * 655
84
75
  @inputs.each do |input|
85
- system("pactl set-sink-input-volume #{input} '#{new_volume}'")
76
+ system("pactl set-sink-input-volume #{input} '#{@volume * 655}'")
86
77
  end
87
78
  end
88
79
 
89
80
  def play_wav
81
+ turn_down_volume
90
82
  system("aplay #{@path}/say_#{@index}.wav > /dev/null 2>&1")
91
83
  end
92
84
 
93
85
  def return_current_volume
94
- if `ps -el | grep aplay | wc -l`.to_i == 0
95
- @inputs.each do |input|
96
- volume = @current_volume * 655
97
- system("pactl set-sink-input-volume #{input} '#{volume}'")
98
- end
99
- set_volume(@current_volume)
86
+ @inputs.each do |input|
87
+ system("pactl set-sink-input-volume #{input} '#{@current_volume * 655}'")
100
88
  end
101
89
  end
102
90
 
@@ -108,15 +96,8 @@ class Fest
108
96
  n = number % 100
109
97
  m = n % 10
110
98
 
111
- if n > 10 && n < 20
112
- return array[2]
113
- elsif m > 1 && m < 5
114
- return array[1]
115
- elsif m == 1
116
- return array[0]
117
- else
118
- return array[2]
119
- end
99
+ n > 10 && n < 20 ? array[2] :
100
+ m > 1 && m < 20 ? array[1] :
101
+ m == 1 ? array[0] : array[2]
120
102
  end
121
-
122
103
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexsey Ermolaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby wrapper for festival scripts
14
14
  email: afay.zangetsu@gmail.com