number_station 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 377a40f8d4aaf4f86503a468bcbb133b10b738d4553e5da6849490150ce41b98
4
- data.tar.gz: 0ba471edeabe6cee234897cc18913aacad818417c39bc5cbc7c5e639e7af6c1e
3
+ metadata.gz: 9ffaf0a85087f356cdd5227039ec8731ff0a89d9cdf7e2a5020bb53cc0be74a6
4
+ data.tar.gz: 88c9c3a558e45684db5f85e0bf32c02ab55b026f146b6b5d2c2816fa6d01f21c
5
5
  SHA512:
6
- metadata.gz: cd740ab71dc7da9f01d81e844c7a71fa6ba5afa6c02eb332f3eb995f71fe6b768617f73149c625b3d0e9d5f1833cc7d0221a66b8f9f13233eeca0b17f89246f8
7
- data.tar.gz: 21d407d3f8db3aa68dfc81265235553d39f6474c96bbdc483960d31396043a12a3d724319b2fc80ccef5de7cbed4227a68847e00b71738d4daf8d17ce71f7ec9
6
+ metadata.gz: a7757a314e15e2fda90ec3689ff63fa45e93a1e0e840c3c3c1a8e8313bb86a6b98acfa464f6ad2c3ed8f15dfbc4f26433fc8bdd2c0ee7795266bd177a81d9632
7
+ data.tar.gz: 9e7885c467a9804e10ae8d478e4ee8d5253c999e8e9fdbc6fef0c632ee182689c48a7184e9897f6245182d38b3e66335f1214dfc33874bb159e55c61d1a025d0
@@ -0,0 +1,36 @@
1
+ def template(word)
2
+ sign = randomsign() || ""
3
+ return "<prosody pitch=\"#{sign + rand(0..80).to_s}\">#{word}</prosody>"
4
+ end
5
+
6
+ def randomsign()
7
+ rnum = rand(0..1)
8
+
9
+ if rnum == 0
10
+ return "-"
11
+ else
12
+ return "+"
13
+ end
14
+ end
15
+
16
+
17
+ message = "This was a triumph! I'm making a note here, huge success."
18
+
19
+ words = message.split(" ")
20
+ sentence = "<speak version=\"1.0\" xmlns=\"\" xmlns:xsi=\"\" xsi:schemaLocation=\"\" xml:lang=\"\"><voice gender=\"female\">"
21
+ sentenceend = "</voice></speak>"
22
+
23
+ words.each do |i|
24
+ sentence += template(i)
25
+ end
26
+
27
+ final = sentence + sentenceend
28
+
29
+
30
+ filename = "GLaDOS_espeak_config.xml"
31
+ f = File.open(filename, "w")
32
+ f.write(final)
33
+ f.close
34
+
35
+ cmd = "espeak -ven+f3 -m -p 60 -s 180 -f #{filename}"
36
+ `#{cmd}`
@@ -24,76 +24,83 @@ require 'fileutils'
24
24
 
25
25
  module NumberStation
26
26
  class CLI < Thor
27
-
27
+
28
28
 
29
29
  # create_config
30
30
  desc "create_config [--path PATH]", "copy the sample config to current directory."
31
31
  long_desc <<-CREATE_CONFIG_LONG_DESC
32
32
  `create_config` will copy the sample config from config/config.json to the current directory. If the
33
- optional parameter `--path PATH` is passed then this file is copied to the location specified by the
33
+ optional parameter `--path PATH` is passed then this file is copied to the location specified by the
34
34
  PATH parameter.
35
+ Sample Intro and Outro messages are also copied to this directory. If you wish to automatically append
36
+ these messages, change the conf.json boolean.
35
37
  CREATE_CONFIG_LONG_DESC
36
38
  option :path, :type => :string
37
39
  def create_config()
40
+ config_file_path = File.join(File.dirname(__FILE__), "../../resources/conf.json")
41
+ intro_file_path = File.join(File.dirname(__FILE__), "../../resources/intro_message.txt")
42
+ outro_file_path = File.join(File.dirname(__FILE__), "../../resources/outro_message.txt")
43
+
44
+ options[:path] ? path = options[:path] : path = File.join(Dir.home, "/number_station")
45
+
46
+ unless Dir.exist?(path) then FileUtils.mkdir(path) end
47
+ unless File.file?(File.join(path, "conf.json")) then FileUtils.cp(config_file_path, File.join(path, "conf.json")) end
48
+ unless File.file?(File.join(path, "intro_message.txt")) then FileUtils.cp(intro_file_path, File.join(path, "intro_message.txt")) end
49
+ unless File.file?(File.join(path, "outro_message.txt")) then FileUtils.cp(outro_file_path, File.join(path, "outro_message.txt")) end
38
50
  NumberStation::ConfigReader.read_config()
39
- config_file_path = File.join(File.dirname(__FILE__), "../../config/conf.json")
40
-
41
- if options[:path]
42
- path = options[:path]
43
- unless File.file?(File.join(path, "/conf.json"))
44
- #write config to path
45
- NumberStation.log.debug "Copying sample config to #{path}"
46
- FileUtils.cp(config_file_path, path)
47
- else
48
- NumberStation.log.debug "File already exists at #{File.join(path, "/conf.json")}"
49
- end
50
- else
51
- path = Dir.pwd
52
- unless File.file?(File.join(path, "/conf.json"))
53
- #write config to local directory the binary was called from
54
- NumberStation.log.debug "Copying sample config to #{path}"
55
- FileUtils.cp(config_file_path, path)
56
- else
57
- NumberStation.log.debug "File already exists at #{File.join(path, "/conf.json")}"
58
- end
59
- end
51
+ NumberStation.log.debug "create_config completed"
60
52
  end
61
53
 
62
54
 
63
55
  # convert_to_phonetic
64
- desc "convert_to_phonetic [MESSAGE]", "Convert a message to phonetic output."
56
+ desc "convert_to_phonetic [MESSAGE_PATH]", "Convert a message to phonetic output."
65
57
  long_desc <<-CONVERT_MESSAGE_LONG_DESC
66
58
  convert_message takes a parameter which should point to a text file containing a message.
59
+ MESSAGE_PATH\n
67
60
  Optional parameters:\n
68
- MESSAGE\n
69
- --intro [INTRO] should be a text file containing intro message.\n
70
- --outro [OUTRO] should be a text file containing the outro message.\n
61
+ --intro [INTRO_PATH] should be a text file containing intro message. Overrides value in conf.json\n
62
+ --outro [OUTRO_PATH] should be a text file containing the outro message. Overrides value in conf.json\n
71
63
  --mp3 [MP3] output message as an mp3 file.
72
-
64
+
73
65
  Final message will be created from intro + message + outro
74
66
  CONVERT_MESSAGE_LONG_DESC
75
67
  option :intro, :type => :string
76
68
  option :outro, :type => :string
77
69
  option :mp3, :type => :string
78
- def convert_to_phonetic(message)
70
+ def convert_to_phonetic(message_path)
79
71
  NumberStation::ConfigReader.read_config()
80
72
 
81
- intro_path = options[:intro]
82
- message_path = message
83
- outro_path = options[:outro]
84
- mp3_path = options[:mp3]
85
- NumberStation.log.debug "intro_path: #{intro_path}" if options[:intro]
73
+ if options[:intro]
74
+ intro_path = options[:intro]
75
+ intro = NumberStation.to_phonetic(intro_path)
76
+ elsif NumberStation.data["resources"]["intro"]["enabled"]
77
+ intro_path = NumberStation.data["resources"]["intro"]["template"]
78
+ intro = NumberStation.to_phonetic(intro_path)
79
+ else
80
+ intro_path = ""
81
+ end
82
+
83
+ if options[:outro]
84
+ outro_path = options[:outro]
85
+ outro = NumberStation.to_phonetic(outro_path)
86
+ elsif NumberStation.data["resources"]["outro"]["enabled"]
87
+ outro_path = NumberStation.data["resources"]["outro"]["template"]
88
+ outro = NumberStation.to_phonetic(outro_path)
89
+ else
90
+ outro_path = ""
91
+ outro = ""
92
+ end
93
+ NumberStation.log.debug "intro enabled: #{NumberStation.data["resources"]["intro"]["enabled"]} path: #{intro_path}"
86
94
  NumberStation.log.debug "message_path: #{message_path}"
87
- NumberStation.log.debug "outro_path: #{outro_path}" if options[:outro]
88
- NumberStation.log.debug "mp3_path: #{mp3_path}" if options[:mp3]
95
+ NumberStation.log.debug "outro enabled: #{NumberStation.data["resources"]["outro"]["enabled"]} path: #{outro_path}"
89
96
 
90
- output = ""
91
- output += NumberStation.to_phonetic(intro_path) if options[:intro]
92
- output += NumberStation.to_phonetic(message_path)
93
- output += NumberStation.to_phonetic(outro_path) if options[:outro]
97
+ message = NumberStation.to_phonetic(message_path)
98
+ output = intro + message + outro
94
99
  NumberStation.log.info "output: #{output}"
95
100
 
96
101
  if options[:mp3]
102
+ mp3_path = options[:mp3]
103
+ NumberStation.log.debug "mp3_path: #{mp3_path}" if options[:mp3]
97
104
  NumberStation.log.debug "Generating mp3 output: #{mp3_path}"
98
105
  NumberStation.write_mp3(output, mp3_path)
99
106
  end
@@ -110,7 +117,7 @@ module NumberStation
110
117
  --numpads NUM\n
111
118
  --length LENGTH
112
119
 
113
- If no parameters are passed it will generate 5 one time pads in the current
120
+ If no parameters are passed it will generate 5 one time pads in the current
114
121
  directory of size 250 characters.
115
122
  MAKE_ONE_TIME_PAD_LONG_DESC
116
123
  option :length, :type => :numeric
@@ -198,5 +205,9 @@ module NumberStation
198
205
  NumberStation::ConfigReader.read_config()
199
206
  NumberStation.log.debug "Version: #{NumberStation::VERSION}"
200
207
  end
208
+
209
+ def self.exit_on_failure?()
210
+ false
211
+ end
201
212
  end
202
213
  end
@@ -24,7 +24,7 @@ module NumberStation
24
24
 
25
25
  def self.read_config()
26
26
  begin
27
- config_file_path = File.join(Dir.pwd, "conf.json")
27
+ config_file_path = File.join(Dir.home, "number_station/conf.json")
28
28
  NumberStation.set_data( JSON.parse(File.read(config_file_path)) )
29
29
  NumberStation.set_log( Logger.new(STDOUT) )
30
30
  NumberStation.log.level = NumberStation.data["logging"]["level"]
@@ -95,7 +95,11 @@ module NumberStation
95
95
 
96
96
 
97
97
  def self.call_espeak(input_file_path, output_file_path)
98
- cmd = "espeak -ven+f3 -m -p 60 -s 180 -f #{input_file_path} --stdout | ffmpeg -i - -ar 44100 -ac 2 -ab 192k -f mp3 #{output_file_path}"
98
+ if NumberStation.data["resources"]["espeak"]["glados"]
99
+ cmd = "espeak -ven+f3 -m -p 60 -s 180 -f #{input_file_path} --stdout | ffmpeg -i - -ar 44100 -ac 2 -ab 192k -f mp3 #{output_file_path}"
100
+ else
101
+ cmd = "espeak -m -p 60 -s 180 -f #{input_file_path} --stdout | ffmpeg -i - -ar 44100 -ac 2 -ab 192k -f mp3 #{output_file_path}"
102
+ end
99
103
 
100
104
  unless NumberStation.command?('espeak') || NumberStation.command?('ffmpeg')
101
105
  NumberStation.log.error "number_station requires the espeak and ffmpeg utilities are installed in order to output an mp3 file."
@@ -106,8 +110,12 @@ module NumberStation
106
110
 
107
111
 
108
112
  def self.write_mp3(message, output_file_path)
109
- filename = NumberStation.data["resources"]["espeak_sentence_template"]
110
- sentence = NumberStation.generate_sentence(message)
113
+ filename = NumberStation.data["resources"]["espeak"]["sentence_template"]
114
+ if NumberStation.data["resources"]["espeak"]["glados"]
115
+ sentence = NumberStation.generate_sentence(message)
116
+ else
117
+ sentence = message
118
+ end
111
119
  NumberStation.write_espeak_template_file(filename, sentence)
112
120
  NumberStation.call_espeak(filename, output_file_path)
113
121
  end
@@ -115,7 +123,7 @@ module NumberStation
115
123
 
116
124
  def self.to_phonetic(file_name)
117
125
  message = ''
118
-
126
+ puts file_name
119
127
  f = File.open(file_name)
120
128
  raw_message = f.read()
121
129
  f.close()
@@ -127,4 +135,4 @@ module NumberStation
127
135
  end
128
136
 
129
137
 
130
- end
138
+ end
@@ -20,5 +20,5 @@
20
20
  =end
21
21
 
22
22
  module NumberStation
23
- VERSION = "0.1.1"
23
+ VERSION = "0.2.0"
24
24
  end
@@ -35,7 +35,7 @@ module NumberStation
35
35
  def self.command?(name)
36
36
  `which #{name}`
37
37
  $?.success?
38
- end
38
+ end
39
39
 
40
40
  def self.set_log(log)
41
41
  @log = log
@@ -56,6 +56,5 @@ Gem::Specification.new do |spec|
56
56
  spec.add_dependency "pastel"
57
57
  spec.add_dependency "thor"
58
58
 
59
- spec.add_development_dependency "bundler", "~> 1.16"
60
- spec.add_development_dependency "rake", "~> 10.0"
59
+ spec.add_development_dependency "rake"
61
60
  end
@@ -0,0 +1,14 @@
1
+ {
2
+ "logging":{
3
+ "level":0
4
+ },
5
+ "server":{
6
+ "host":"0.0.0.0",
7
+ "port":8080
8
+ },
9
+ "resources":{
10
+ "espeak": {"sentence_template": "/tmp/espeak_tmp.xml", "glados":false},
11
+ "intro": {"template":"intro_message.txt", "enabled":true},
12
+ "outro": {"template":"outro_message.txt", "enabled":true}
13
+ }
14
+ }
@@ -1 +1 @@
1
- ei7htb ei7htb
1
+ sample intro message
@@ -1 +1 @@
1
- ei7htb ei7htb
1
+ sample outro message
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: number_station
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kirwan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-11-29 00:00:00.000000000 Z
@@ -38,34 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.16'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.16'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: '0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: '0'
69
55
  description: "(WIP) A collection of utilities to aid in running your own number station!"
70
56
  email:
71
57
  - davidkirwanirl@gmail.com
@@ -86,8 +72,8 @@ files:
86
72
  - README.asciidoc
87
73
  - Rakefile
88
74
  - bin/number_station
89
- - config/conf.json
90
75
  - lib/number_station.rb
76
+ - lib/number_station/GLaDOS_espeak.rb
91
77
  - lib/number_station/cli.rb
92
78
  - lib/number_station/config_reader.rb
93
79
  - lib/number_station/decrypt_message.rb
@@ -96,7 +82,7 @@ files:
96
82
  - lib/number_station/phonetic_conversion.rb
97
83
  - lib/number_station/version.rb
98
84
  - number_station.gemspec
99
- - resources/body_message.txt
85
+ - resources/conf.json
100
86
  - resources/intro_message.txt
101
87
  - resources/outro_message.txt
102
88
  homepage: https://rubygems.org/gems/number_station
@@ -104,7 +90,7 @@ licenses:
104
90
  - GPL 3.0
105
91
  metadata:
106
92
  allowed_push_host: https://rubygems.org
107
- post_install_message:
93
+ post_install_message:
108
94
  rdoc_options: []
109
95
  require_paths:
110
96
  - lib
@@ -119,8 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
105
  - !ruby/object:Gem::Version
120
106
  version: '0'
121
107
  requirements: []
122
- rubygems_version: 3.0.3
123
- signing_key:
108
+ rubygems_version: 3.0.9
109
+ signing_key:
124
110
  specification_version: 4
125
111
  summary: "(WIP) Run your own number station!"
126
112
  test_files: []
data/config/conf.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "logging":{
3
- "level":0
4
- },
5
- "server":{
6
- "host":"localhost",
7
- "port":8080
8
- },
9
- "resources":{
10
- "espeak_sentence_template":"/tmp/GLaDOS_template.xml"
11
- }
12
- }
@@ -1 +0,0 @@
1
- 1234abcd 5678efgh