Class: Video

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/video.rb

Overview

The video class has an attachment file using the paperclip gem it also invokes methods of the speech to text API to send the video and retrieve transcription.

Instance Method Summary collapse

Instance Method Details

#check_is_video_processedObject

a method to check if the video as been processed by the text to speech API No return updates the is_processed video attribute in database if saves transcription into database

Parameters:

  • (spoken data uid)

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/video.rb', line 47

def check_is_video_processed
  spokenDataAPIObject = SpokenDataAPI.new(ENV['SPOKEN_DATA_USER_ID'],ENV['SPOKEN_DATA_API_TOKEN'])

  @response = spokenDataAPIObject.recording_processed?(self.uid)

  @video =  Video.find_by_uid(self.uid)

  if @response == false
    @video.is_processed = false
    @video.save
  else
    if @video.is_processed == false

      @video.parse_srt_and_save_into_db(self.uid)
      @video.is_processed = true
      @video.save
    end
  end

end

#convert_srt_to_word_accurate_hypertranscript(srt_string) ⇒ Object


102
103
104
105
106
# File 'app/models/video.rb', line 102

def convert_srt_to_word_accurate_hypertranscript(srt_string)
  htConverter= HypertranscriptConverter.new
  ht_data_structure= htConverter.parse_srt_String(srt_string)
  return ht_data_structure
end

#delete_video_from_speech_to_text_apiObject

as the name sudgests, a method to delete a video file fromt he speech to text api


95
96
97
98
# File 'app/models/video.rb', line 95

def delete_video_from_speech_to_text_api
    spokenDataAPIObject = SpokenDataAPI.new(ENV['SPOKEN_DATA_USER_ID'],ENV['SPOKEN_DATA_API_TOKEN'])
    spokenDataAPIObject.delete_recording(self.uid)
end

#parse_srt_and_save_into_db(video_uid) ⇒ Object

retrieve and parse srt file from speech to text API to save into database

Parameters:

  • (spoken data uid)

71
72
73
74
75
76
# File 'app/models/video.rb', line 71

def parse_srt_and_save_into_db(video_uid)
  spokenDataAPIObject = SpokenDataAPI.new(ENV['SPOKEN_DATA_USER_ID'],ENV['SPOKEN_DATA_API_TOKEN'])
  subtitles_srt_string = spokenDataAPIObject.retrieve_subtitles_srt(video_uid)
  hyper_transcript_hash = convert_srt_to_word_accurate_hypertranscript(subtitles_srt_string)
  save_to_db(hyper_transcript_hash)
end

#s3_credentialsObject


15
16
17
# File 'app/models/video.rb', line 15

def s3_credentials
  {:bucket =>  ENV['AMAZON_S3_BUCKET'], :access_key_id => ENV['AMAZON_S3_ACCESS_KEY_ID'], :secret_access_key =>  ENV['AMAZON_S3_SECRET_ACCESS_KEY']}
end

#save_to_db(hyper_transcript_hash) ⇒ Object

saves hypertranscript data structure, ruby hash, into database.

Parameters:

  • (ruby hash, hypertranscript data structure)

81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/video.rb', line 81

def save_to_db(hyper_transcript_hash)
  @transcription = self.transcriptions.create(:name=>"Transcription_#{Time.now}")
  line_number = 0
  hyper_transcript_hash.each do |one_line|
    @line = @transcription.lines.create
    one_line.each do |l|
      @line.words.create(:tc_in => l['tc_in'], :tc_out => l['tc_out'], :word => l['word'])
    end
  end

end

#send_to_text_to_speechObject


34
35
36
37
38
39
# File 'app/models/video.rb', line 34

def send_to_text_to_speech
  spoken_data_api_object = SpokenDataAPI.new(ENV['SPOKEN_DATA_USER_ID'],ENV['SPOKEN_DATA_API_TOKEN'])
  uid = spoken_data_api_object.send_by_video_url(self.link.to_s)
  self.uid = uid
  self.save
end