Permalink
Browse files

- add transcription

  • Loading branch information...
1 parent 8a82d49 commit 222eedc6ed99cad2460d7e30161dada7ec96e39e @sr3d committed Jan 29, 2012
@@ -10,27 +10,21 @@ def index
xml = <<-XML
<Response>
<Say>Please leave a message at the beep. Press the hash or pound key when finished.</Say>
- <Record action="/twilio_callback/receive_voice_recording.xml" method="GET" maxLength="300" finishOnKey="#" />
+ <Record action="/twilio_callback/receive_voice_recording.xml" method="GET" maxLength="300" finishOnKey="#"
+ transcribeCallback="/twilio_callback/receive_transcription.xml"
+ />
<Say>I did not receive any recording. Please try again.</Say>
</Response>
XML
# Handling default
elsif
-
# Started GET "/twilio_callback/index.xml?AccountSid=AC598c05e863827c7a7fffa351490f10d2&ToZip=94949&FromState=IL&Called=%2B14155992671&FromCountry=US&CallerCountry=US&CalledZip=94949&Direction=inbound&FromCity=LAKE+FOREST&CalledCountry=US&CallerState=IL&CallSid=CA3de81bdf7ac3bc59090a3cace03b97c5&CalledState=CA&From=%2B12244361127&CallerZip=60037&FromZip=60037&CallStatus=in-progress&ToCity=NOVATO&ToState=CA&To=%2B14155992671&ToCountry=US&CallerCity=LAKE+FOREST&ApiVersion=2010-04-01&Caller=%2B12244361127&CalledCity=NOVATO&DialStatus=answered" for 127.0.0.1 at 2012-01-28 17:52:55 -0800
# Processing by TwilioCallbackController#index as XML
# Parameters: {"AccountSid"=>"AC598c05e863827c7a7fffa351490f10d2", "ToZip"=>"94949", "FromState"=>"IL", "Called"=>"+14155992671", "FromCountry"=>"US", "CallerCountry"=>"US", "CalledZip"=>"94949", "Direction"=>"inbound", "FromCity"=>"LAKE FOREST", "CalledCountry"=>"US", "CallerState"=>"IL", "CallSid"=>"CA3de81bdf7ac3bc59090a3cace03b97c5", "CalledState"=>"CA", "From"=>"+12244361127", "CallerZip"=>"60037", "FromZip"=>"60037", "CallStatus"=>"in-progress", "ToCity"=>"NOVATO", "ToState"=>"CA", "To"=>"+14155992671", "ToCountry"=>"US", "CallerCity"=>"LAKE FOREST", "ApiVersion"=>"2010-04-01", "Caller"=>"+12244361127", "CalledCity"=>"NOVATO", "DialStatus"=>"answered"}
# User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'alexle@marrily.com' LIMIT 1
# Rendered text template (0.0ms)
# Completed 200 OK in 7ms (Views: 1.0ms | ActiveRecord: 0.4ms)
-
-
- # <Gather action="handle-screen-input.php" numDigits="1">
- # <Say>You have an incoming call.</Say>
- # <Say>To accept the call, press 1.</Say>
- # <Say>To reject the call, press any other key.</Say>
- # </Gather>
xml = <<-XML
<Response>
<Gather action="/twilio_callback/index.xml" method="GET" numDigits="1">
@@ -54,8 +48,7 @@ def receive_voice_recording
# "ToCity"=>"NOVATO", "ToState"=>"CA", "RecordingUrl"=>"http://api.twilio.com/2010-04-01/Accounts/AC598c05e863827c7a7fffa351490f10d2/Recordings/REe0a2e683a142a1e2f766801b574d4e53", "To"=>"+14155992671", "Digits"=>"#", "ToCountry"=>"US",
# "RecordingDuration"=>"15", "CallerCity"=>"LAKE FOREST", "ApiVersion"=>"2010-04-01", "Caller"=>"+12244361127",
# "CalledCity"=>"NOVATO", "RecordingSid"=>"REe0a2e683a142a1e2f766801b574d4e53"}
-
- audio = @user.audios.create :url => params[:RecordingUrl], :duration => params[:RecordingDuration]
+ audio = @user.audios.create :url => params[:RecordingUrl], :duration => params[:RecordingDuration], :recording_sid => params[:RecordingSid]
interview = @user.interviews.create :audio_id => audio.id
# audio = @user.audiointerview.audio.new :url => params[:RecordingUrl], :duration => params[:RecordingDuration], :user_id => @user.id
respond_to do |format|
@@ -64,14 +57,25 @@ def receive_voice_recording
<Response>
<Gather action="/twilio_callback/index.xml" method="GET" numDigits="#">
<Say>Awesome! Your voice interview has been saved. Hit Hash or Pound to return to the index page.</Say>
- </Gather>
+ </Gather>
</Response>
XML
render :text => xml
end
end
end
+ def receive_transcription
+ audio = Audio.find_by_recording_sid params[:RecordingSid]
+ # update with the transcription
+ audio.update_attribute :transcription, params[:TranscriptionText]
+ respond_to do |format|
+ format.xml do
+ render :xml => '<Response></Response>'
+ end
+ end
+ end
+
private
def find_user
@user = current_user = User.find_by_phone(params[:From])
View
@@ -1,5 +1,8 @@
class Audio < ActiveRecord::Base
belongs_to :user
- attr_accessible :user_id, :url, :description, :duration
-
+ attr_accessible :user_id, :url, :description, :duration, :recording_sid, :transcription
+
+ def has_transcription?
+ !transcription.nil?
+ end
end
View
@@ -1,17 +1,30 @@
class Interview < ActiveRecord::Base
- belongs_to :user
+ belongs_to :user
belongs_to :audio
+ # belongs_to :video
+ # belongs_to :photos
+ # belongs_to :text
+
def audio?
!audio_id.nil?
end
def duration
- audio ? audio.duration : video.duration
+ audio? ? audio.duration : video.duration
end
def url
- audio ? audio.url : video.url
+ audio? ? audio.url : video.url
end
+ def has_transcription?
+ audio? ? audio.has_transcription? : video.has_transcription?
+ end
+
+ def transcription
+ audio? ? audio.transcription : video.transcription
+ end
+
+
end
@@ -20,6 +20,22 @@
</div><!-- .module_wrapper -->
</div>
+
+ <% if @interview.has_transcription? %>
+ <div class="grid_10">
+ <div class="module_wrapper">
+ <div class="module_header">
+ <div>Transcription</div>
+ </div><!-- .module_header -->
+ <div class="module_padding">
+ <%= @interview.transcription %>
+ </div><!-- .module_padding -->
+ </div><!-- .module_wrapper -->
+ </div>
+ <% end %>
+
+
+
<div class="grid_10">
<div class="module_wrapper">
<div class="module_header">
@@ -36,11 +52,3 @@
<div class="clear"></div>
</div><!-- .padding -->
-
-
-<script type="text/javascript">
-FB.Event.subscribe('comment.create', function(response) {
- // console.log("response %o",response);
- // do something with response.session
-});
-</script>
View
@@ -3,6 +3,8 @@
get "twilio_callback/index"
post "twilio_callback/index"
get "twilio_callback/receive_voice_recording"
+ get "twilio_callback/receive_transcription"
+ post "twilio_callback/receive_transcription"
# get "comments/create"
#
@@ -0,0 +1,13 @@
+class AddRsidAndTranscriptionToAudios < ActiveRecord::Migration
+ def self.up
+ add_column :audios, :recording_sid, :string
+ add_column :audios, :transcription, :text
+
+ add_index :audios, :recording_sid
+ end
+
+ def self.down
+ remove_column :audios, :recording_sid
+ remove_column :audios, :transcription
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120129040739) do
+ActiveRecord::Schema.define(:version => 20120129085842) do
create_table "admins", :force => true do |t|
t.string "email", :default => "", :null => false
@@ -48,11 +48,15 @@
t.integer "user_id"
t.string "url"
t.text "description"
- t.integer "duration", :default => 0
+ t.integer "duration", :default => 0
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "recording_sid"
+ t.text "transcription"
end
+ add_index "audios", ["recording_sid"], :name => "index_audios_on_recording_sid"
+
create_table "authentications", :force => true do |t|
t.integer "user_id"
t.string "provider"

0 comments on commit 222eedc

Please sign in to comment.