speaker_text 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Derrick Parkhurst
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ SpeakerText Gem
2
+ ===============
3
+
4
+ A gem to automate transcription of audio and video media using the [SpeakerText service](http://speakertext.com)
5
+ and [SpeakerText API](http://speakertext.com/api).
6
+
7
+ Overview
8
+ --------
9
+
10
+ Audio and video media hosted on the Internet are not well indexed by search engines and thus not easily
11
+ searchable. For a fee, the SpeakerText.com service produces text transcripts of audio and video content that
12
+ is available on the Internet (on a private website or a media hosting service such as YouTube). These text
13
+ transcripts can be used to augment media, thus making them searchable and indexed by search engines. Using
14
+ the SpeakerText video player, the trascripts can also be used as subtitles increasing access of audio and
15
+ video media to hearing impared individuals.
16
+
17
+ Requires
18
+ --------
19
+
20
+ * A SpeakerText account and API key
21
+ * Credits purchased through the [SpeakerText website](http://speakertext.com)
22
+ * [HTTParty gem](http://github.com/jnunemaker/httparty)
23
+ * [UUIDTools gem](http://github.com/sporkmonger/uuidtools)
24
+ * Ruby >= 1.9.2
25
+
26
+ Usage Examples
27
+ --------------
28
+
29
+ Install
30
+
31
+ gem install speakertext
32
+
33
+ Initialize the API with a key
34
+
35
+ require 'speaker_text'
36
+ st = SpeakerText.new(your_api_key)
37
+
38
+ Submit a media file URL for transcription
39
+
40
+ success, transcript_id = st.transcribe(url: public_url_of_media_file)
41
+
42
+ Submit a media file hosted on a platform (e.g., YouTube, Vimeo, SoundCloud)
43
+
44
+ status, transcript_id = st.transcribe(platform: 'youtube', id: youtube_video_id)
45
+
46
+ Check the status of the transcription process
47
+
48
+ success, status = st.transcript_status(id: transcript_id)
49
+
50
+ Request the completed transcripts
51
+
52
+ success, content = st.transcript(id: transcript_id)
53
+
54
+ See also the [examples](https://github.com/thirtysixthspan/speakertext/tree/master/examples)
55
+
56
+
57
+ License
58
+ -------
59
+ Copyright (c) 2011 Derrick Parkhurst (derrick.parkhurst@gmail.com)
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining a copy
62
+ of this software and associated documentation files (the "Software"), to deal
63
+ in the Software without restriction, including without limitation the rights
64
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
65
+ copies of the Software, and to permit persons to whom the Software is
66
+ furnished to do so, subject to the following conditions:
67
+
68
+ The above copyright notice and this permission notice shall be included in
69
+ all copies or substantial portions of the Software.
70
+
71
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
72
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
73
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
74
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
76
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
77
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'speaker_text'
4
+
5
+ if ARGV.size<1
6
+ puts "#{$0} [SpeakerText Transcript ID]"
7
+ exit
8
+ end
9
+
10
+ id = ARGV[0]
11
+ puts "Fetching SpeakerText transcript ID #{id}"
12
+
13
+ config_file = 'speakertext.yaml'
14
+ if File.exist?(config_file)
15
+ config = YAML::load(File.open(config_file))
16
+ else
17
+ puts "Failed to load #{config_file}"
18
+ exit
19
+ end
20
+
21
+ if !config.include?('api_key') || config['api_key']==''
22
+ puts "You must provide an api_key in #{config_file}"
23
+ exit
24
+ end
25
+
26
+ st = SpeakerText.new(config['api_key'])
27
+ success, content = st.fetch_xml_transcript(id: id)
28
+ if success
29
+ filename = "#{id}.xml"
30
+ File.open(filename, 'w') do |file|
31
+ file.write(content)
32
+ end
33
+ puts "Success: saved transcript to #{filename}"
34
+ else
35
+ puts "Error: #{content}"
36
+ end
37
+
38
+
39
+
@@ -0,0 +1 @@
1
+ api_key:
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'speaker_text'
4
+
5
+ if ARGV.size<1
6
+ puts "#{$0} [Public URL of audio of video file]"
7
+ exit
8
+ end
9
+
10
+ url = ARGV[0]
11
+ puts "Uploading #{url} to SpeakerText for transcription"
12
+
13
+ config_file = 'speakertext.yaml'
14
+ if File.exist?(config_file)
15
+ config = YAML::load(File.open(config_file))
16
+ else
17
+ puts "Failed to load #{config_file}"
18
+ exit
19
+ end
20
+
21
+ if !config.include?('api_key') || config['api_key']==''
22
+ puts "You must provide an api_key in #{config_file}"
23
+ exit
24
+ end
25
+
26
+ st = SpeakerText.new(config['api_key'])
27
+ success, transcript_id = st.transcribe(url: url)
28
+ if success
29
+ puts "Success: Transcript ID is #{transcript_id}"
30
+ else
31
+ puts "Error: #{transcript_id}"
32
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'speaker_text'
4
+
5
+ if ARGV.size<1
6
+ puts "#{$0} [YouTube Video ID]"
7
+ exit
8
+ end
9
+
10
+ video_id = ARGV[0]
11
+ puts "Uploading to SpeakerText from YouTube. Video ID #{video_id}"
12
+
13
+ config_file = 'speakertext.yaml'
14
+ if File.exist?(config_file)
15
+ config = YAML::load(File.open(config_file))
16
+ else
17
+ puts "Failed to load #{config_file}"
18
+ exit
19
+ end
20
+
21
+ if !config.include?('api_key') || config['api_key']==''
22
+ puts "You must provide an api_key in #{config_file}"
23
+ exit
24
+ end
25
+
26
+ st = SpeakerText.new(config['api_key'])
27
+ status, transcript_id = st.transcribe(platform: 'youtube', id: video_id)
28
+ if status
29
+ puts "Success: Transcript ID is #{transcript_id}"
30
+ else
31
+ puts "Error: #{transcript_id}"
32
+ end
33
+
@@ -0,0 +1,138 @@
1
+ require 'httparty'
2
+ require 'uuidtools'
3
+ require 'json'
4
+
5
+ class SpeakerText
6
+ include HTTParty
7
+ base_uri "https://api.speakertext.com/v1"
8
+ VERSION = '1.0.0'
9
+
10
+ def initialize(api_key)
11
+ self.class.basic_auth api_key,'x'
12
+ @verbose=false
13
+ end
14
+
15
+ def verbose
16
+ @verbose=true
17
+ end
18
+
19
+ def generate_id()
20
+ UUIDTools::UUID.random_create.to_s
21
+ end
22
+
23
+ def remote_file_exists(url)
24
+ response = HTTParty.head(url)
25
+ return true if response.code == 200
26
+ false
27
+ end
28
+
29
+ def submit_transcription_request(query)
30
+ puts query if @verbose
31
+ response = self.class.post("/transcripts", :query => query)
32
+ return [false, "Unauthorized: API key is incorrect"] if response.code==401
33
+ return [false, "SpeakerText Internal Error"] if response.code==500
34
+
35
+ fields = JSON.parse response.body
36
+
37
+ return [false, fields['message']] if response.code != 201
38
+ return [true, fields['transcript_ids'][0]]
39
+ end
40
+
41
+ def transcribe_platform(args)
42
+ puts "Transcribe Platform" if @verbose
43
+ platform = args[:platform]
44
+ source_id = args[:id]
45
+ return [false, "Source id from #{platform} required"] unless source_id && source_id!=''
46
+ source_annotation = args[:annotation] || ''
47
+
48
+ sources = {:platform => platform,
49
+ :video_id => source_id,
50
+ :annotation => source_annotation
51
+ }
52
+
53
+ query = {}
54
+ query[:sources] = sources.to_json
55
+ query[:pingback_url] = args[:pingback_url] if args.include?(:pingback_url)
56
+ submit_transcription_request(query)
57
+ end
58
+
59
+ def transcribe_url(args)
60
+ puts "Transcribe URL" if @verbose
61
+ url = args[:url]
62
+ return [false, "Cannot access remote file #{url}."] if !remote_file_exists(url)
63
+ source_id = args[:id] || generate_id()
64
+ source_title = args[:title] || File.basename(url)
65
+ source_thumbnail_url = args[:thumb_url] || ''
66
+ return [false, "Cannot access remote thumbnail file #{url}."] if args.include?(:thumb_url) &&
67
+ args[:thumb_url]!='' &&
68
+ !remote_file_exists(thumb_url)
69
+ source_annotation = args[:annotation] || ''
70
+
71
+ sources = {:url => url,
72
+ :ref_id => source_id,
73
+ :title => source_title,
74
+ :thumb_url => source_thumbnail_url,
75
+ :annotation => source_annotation
76
+ }
77
+
78
+ query = {}
79
+ query[:sources] = sources.to_json
80
+ query[:pingback_url] = args[:pingback_url] if args.include?(:pingback_url)
81
+ submit_transcription_request(query)
82
+ end
83
+
84
+ def transcribe(args)
85
+ return transcribe_url(args) if args.include?(:url)
86
+ return transcribe_platform(args) if args.include?(:platform)
87
+ "Missing arguments to transcribe request"
88
+ end
89
+
90
+ def transcript(args)
91
+ id = args[:id]
92
+ return [false, 'transcript id required'] unless id && id!=''
93
+
94
+ format = args[:format] || 'xml'
95
+
96
+ response = self.class.get("/transcripts/#{id}", :query => { format: format })
97
+ return [false, "Unauthorized: API key is incorrect"] if response.code==401
98
+ return [false, "SpeakerText Internal Error"] if response.code==500
99
+
100
+ fields = JSON.parse response.body
101
+
102
+ return [false, fields['message']] if response.code != 200
103
+ return [false, fields['status']] if fields['content']==''
104
+ return [true, fields['content']]
105
+ end
106
+
107
+ def fetch_transcript(args)
108
+ transcript(args)
109
+ end
110
+
111
+ def fetch_xml_transcript(args)
112
+ args.merge(format: 'xml')
113
+ transcript(args)
114
+ end
115
+
116
+ def fetch_text_transcript(args)
117
+ args.merge(format: 'txt')
118
+ transcript(args)
119
+ end
120
+
121
+ def fetch_html_transcript(args)
122
+ args.merge(format: 'html')
123
+ transcript(args)
124
+ end
125
+
126
+ def transcript_status(args)
127
+ id = args[:id]
128
+
129
+ response = self.class.get("/transcripts/#{id}")
130
+ return [false, "SpeakerText Internal Error"] if response.code==500
131
+
132
+ fields = JSON.parse response.body
133
+
134
+ return [false, fields['message']] if response.code != 200
135
+ return [true, fields['status']]
136
+ end
137
+
138
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speaker_text
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Derrick Parkhurst
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-24 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: uuidtools
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.1
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: A gem to automate transcription of audio and video media using the SpeakerText.com service.
38
+ email: derrick.parkhurst@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - lib/speaker_text.rb
47
+ - examples/transcribe_video.rb
48
+ - examples/transcribe_youtube_video.rb
49
+ - examples/speakertext.yaml
50
+ - examples/fetch_transcript.rb
51
+ - LICENSE
52
+ - README.md
53
+ homepage: http://github.com/thritysixthspan/speakertext
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.11
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: SpeakerText API Wrapper Gem
80
+ test_files: []
81
+