Class: Wco::Newspartial
- Inherits:
-
Object
- Object
- Wco::Newspartial
- Includes:
- Mongoid::Document, Mongoid::Paperclip, Mongoid::Paranoia, Mongoid::Timestamps, Utils
- Defined in:
- app/models/wco/newspartial.rb
Constant Summary collapse
- PAGE_PARAM_NAME =
'newspartials_page'
Instance Method Summary collapse
- #config ⇒ Object
- #duration_ms ⇒ Object
- #generate_speech ⇒ Object
-
#generate_video ⇒ Object
Can I make do without puppet driver? Probably not: I need the audio worklet.
- #video ⇒ Object
Methods included from Utils
Instance Method Details
#config ⇒ Object
54 55 56 |
# File 'app/models/wco/newspartial.rb', line 54 def config @config ||= JSON.parse self[:config_json] end |
#duration_ms ⇒ Object
57 58 59 |
# File 'app/models/wco/newspartial.rb', line 57 def duration_ms duration = config['vtimes'].last.to_i + config['vdurations'].last.to_i rescue 0 end |
#generate_speech ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/wco/newspartial.rb', line 61 def generate_speech out = HTTParty.post( "#{HEAD_TTS_ORIGIN}/v1/synthesize", headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', }, body: { input: body, voice: "af_bella", language: "en-us", audioEncoding: "wav", }.to_json ); out = out.body puts! out, 'out' self[:config_json] = out tmp = JSON.parse( out ) decoded_audio = Base64.decode64( tmp['audio'] ) temp_file = Tempfile.new(['speech', '.wav']) temp_file.binmode temp_file.write(decoded_audio) temp_file.rewind self.audio = temp_file temp_file.close temp_file.unlink tmp.delete('audio') self[:speech_json] = tmp.to_json self.save return out end |
#generate_video ⇒ Object
Can I make do without puppet driver? Probably not: I need the audio worklet.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/wco/newspartial.rb', line 98 def generate_video cmd = "cd #{ISHLIB3JS_ROOT} ; node ./src/talking_head/example_puppeteer_wired.js \ --api_key=#{WCO_SIMPLE_API_KEY} \ --api_secret=#{WCO_SIMPLE_API_SECRET} \ --wco_origin=#{WCO_ORIGIN} \ --w_px=#{newsvideo.w_px} \ --h_px=#{newsvideo.h_px} \ --newspartial_id=#{self[:id]} "; puts "+++ cmd:" puts cmd begin out = `#{cmd}` rescue err puts! err, 'err' end puts! out, 'out' return out end |