-
Notifications
You must be signed in to change notification settings - Fork 0
/
kq_speak.rb
86 lines (73 loc) · 1.74 KB
/
kq_speak.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Programming Language KQ
# with modification to speak
# original source by @nvsofts http://ideone.com/DDWfy
# twitter: http://ideone.com/DDWfy
require 'moji'
input_org = STDIN.readlines.join.chomp
input = input_org.force_encoding('UTF-8').tr('^ダァシエリイェス', '')
## say
da = Moji.han_to_zen(input_org).split(/[\r\n]/).join("").split("!")
#da = Moji.han_to_zen(input_org).split(/[\r\n]/).join("")
#puts da
#command = 'SayKana -s 170 -o da.aiff' + da
da.each do |l|
next if l == ""
l += "!"
puts Moji.zen_to_han(l)
command = 'SayKana -s 170 ' + l
system(command)
end
## put
if input.length % 6 != 0 then
puts "プログラムが不正です"
exit(1)
end
buffer = Array.new(32768, 0)
ptr = 0
run_ptr = 0
while run_ptr != input.length
case input[run_ptr, 6]
when 'ダァイェス' # >
ptr += 1
when 'イェスダァ' # <
ptr -= 1
when 'ダァダァ' # +
buffer[ptr] += 1
when 'シエリシエリ' # -
buffer[ptr] -= 1
when 'ダァシエリ' # ,
buffer[ptr] = STDIN.getc
when 'シエリダァ' # .
print buffer[ptr].chr
when 'シエリイェス' # [
if buffer[ptr] == 0 then
nest = 1
while nest != 0
run_ptr += 6
case input[run_ptr, 6]
when 'シエリイェス'
nest += 1
when 'イェスシエリ'
nest -= 1
end
end
end
when 'イェスシエリ' # ]
if buffer[ptr] != 0 then
nest = 1
while nest != 0
run_ptr -= 6
case input[run_ptr, 6]
when 'シエリイェス'
nest -= 1
when 'イェスシエリ'
nest += 1
end
end
run_ptr -= 6
end
end
run_ptr += 6
end