Class: Wco::Newspartial
- Inherits:
-
Object
- Object
- Wco::Newspartial
- Includes:
- Mongoid::Document, Mongoid::Paperclip, 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
53 54 55 |
# File 'app/models/wco/newspartial.rb', line 53 def config @config ||= JSON.parse self[:config_json] end |
#duration_ms ⇒ Object
56 57 58 |
# File 'app/models/wco/newspartial.rb', line 56 def duration_ms duration = config['vtimes'].last.to_i + config['vdurations'].last.to_i rescue 0 end |
#generate_speech ⇒ Object
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 85 86 87 88 89 90 91 92 |
# File 'app/models/wco/newspartial.rb', line 60 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/wco/newspartial.rb', line 97 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 |