Class: Discordrb::Voice::Encoder
- Inherits:
-
Object
- Object
- Discordrb::Voice::Encoder
- Defined in:
- lib/discordrb/voice/encoder.rb
Overview
Wrapper class around opus-ruby
Instance Attribute Summary collapse
-
#volume ⇒ Object
Returns the value of attribute volume.
Instance Method Summary collapse
- #destroy ⇒ Object
- #encode(buffer) ⇒ Object
- #encode_file(file) ⇒ Object
- #encode_io(io) ⇒ Object
-
#initialize ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize ⇒ Encoder
Returns a new instance of Encoder.
9 10 11 12 13 14 15 |
# File 'lib/discordrb/voice/encoder.rb', line 9 def initialize @sample_rate = 48_000 @frame_size = 960 @channels = 2 @volume = 1.0 @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels) end |
Instance Attribute Details
#volume ⇒ Object
Returns the value of attribute volume.
7 8 9 |
# File 'lib/discordrb/voice/encoder.rb', line 7 def volume @volume end |
Instance Method Details
#destroy ⇒ Object
21 22 23 |
# File 'lib/discordrb/voice/encoder.rb', line 21 def destroy @opus.destroy end |
#encode(buffer) ⇒ Object
17 18 19 |
# File 'lib/discordrb/voice/encoder.rb', line 17 def encode(buffer) @opus.encode(buffer, 1920) end |
#encode_file(file) ⇒ Object
25 26 27 28 |
# File 'lib/discordrb/voice/encoder.rb', line 25 def encode_file(file) command = "ffmpeg -loglevel 0 -i #{file.path} -f s16le -ar 48000 -ac 2 -af volume=#{@volume} pipe:1" IO.popen(command) end |
#encode_io(io) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/discordrb/voice/encoder.rb', line 30 def encode_io(io) ret_io, writer = IO.pipe command = "ffmpeg -loglevel 0 -i - -f s16le -ar 48000 -ac 2 -af volume=#{@volume} pipe:1" spawn(command, in: io, out: writer) ret_io end |