Last active
September 21, 2015 20:46
-
-
Save nogweii/45f2b2fcaf2699818fea to your computer and use it in GitHub Desktop.
mumble razzle hatbot play whole function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mumble | |
class Client | |
def conn | |
@conn | |
end | |
def config | |
@config | |
end | |
end | |
end | |
class MyAudioPlayer < Mumble::AudioPlayer | |
attr_reader :queue, :file | |
attr_accessor :playing | |
public :consume | |
def bounded_encode | |
@file.each_buffer(@encoder.frame_size) do |buffer| | |
puts "Encoding #{buffer.samples.size} samples as OPUS..." | |
encode_sample buffer.samples.pack('s*') | |
end | |
end | |
def read_wav(file) | |
puts "Reading wav #{file} as a #{@wav_format}." | |
@file = WaveFile::Reader.new(file, @wav_format) | |
end | |
end | |
@audio_streamer = MyAudioPlayer.new Mumble::Client::CODEC_OPUS, | |
$client.conn, | |
$client.config.sample_rate, | |
$client.config.bitrate | |
def play_whole_file(wav_path) | |
unless @audio_streamer.playing? | |
@audio_streamer.playing = true | |
@audio_streamer.read_wav(wav_path) | |
@audio_streamer.bounded_encode | |
while !@audio_streamer.queue.empty? | |
puts "Consuming part of the audio queue..." | |
@audio_streamer.consume | |
end | |
@audio_streamer.stop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment