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'- MAX_WORDS =
30
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
57 58 59 |
# File 'app/models/wco/newspartial.rb', line 57 def config @config ||= JSON.parse self[:config_json] end |
#duration_ms ⇒ Object
60 61 62 |
# File 'app/models/wco/newspartial.rb', line 60 def duration_ms duration = config['vtimes'].last.to_i + config['vdurations'].last.to_i rescue 0 end |
#generate_speech ⇒ Object
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 94 95 96 97 98 |
# File 'app/models/wco/newspartial.rb', line 64 def generate_speech out = HTTParty.post( "#{Wco::Setting.get('HEAD_TTS_ORIGIN')}/v1/synthesize", headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', }, body: { input: body, # voice: "am_fenrir", # good? # "af_bella" # bad voice: "af_jessica", # good 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. uses ishlib3js v0.0.2, not 0.1.0!!! @deprecated, this is being brought into wco_models
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/models/wco/newspartial.rb', line 105 def generate_video cmd = "cd #{Wco::Setting.get('ISHLIB3JS_ROOT')} ; node ./src/talking_head/example_puppeteer_wired.js \ --api_key=#{Wco::Setting.get('WASYACO_SIMPLE_API_KEY')} \ --api_secret=#{Wco::Setting.get('WASYACO_SIMPLE_API_SECRET')} \ --wco_origin=#{Wco::Setting.get('WASYACO_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 |