speaker_text_api 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21a093f357bbb06adfe393bed2027565b41ad58b
4
+ data.tar.gz: 34d3f356d0c9d87634e0b026f8946bbcbaaecb30
5
+ SHA512:
6
+ metadata.gz: e042f3759b8150151f557732c97c4f361b8654a4dd3106a56561351043a3ff6ad0cda6272b090fce39f90206aaea91f16a6b88565a218fbb54f42cfce935602c
7
+ data.tar.gz: 5f2f9362b8b533d1b32a51d5c2ed1f255bc006cd9b66151bec993ea60c7ca97951fd2b0482bda9863cdda682eb6e2ac4afd8a5aa6dabdfa7e845a6237cffea1c
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Rojesh Shrestha
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,53 @@
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://app.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
+
18
+ Requires
19
+ --------
20
+
21
+ * A SpeakerText account and API key
22
+ * Credits purchased through the [SpeakerText website](http://speakertext.com)
23
+ * [HTTParty gem](http://github.com/jnunemaker/httparty)
24
+ * [UUIDTools gem](http://github.com/sporkmonger/uuidtools)
25
+ * Ruby >= 1.9.2
26
+
27
+ Usage Examples
28
+ --------------
29
+
30
+ Install
31
+
32
+ gem install speaker_text_api
33
+
34
+ Initialize the API with a key
35
+
36
+ require 'speaker_text_api'
37
+ st = SpeakerTextApi.new(your_api_key)
38
+
39
+ Submit a media file URL for transcription
40
+
41
+ success, transcript_id = st.transcribe(url: public_url_of_media_file)
42
+
43
+ Submit a media file hosted on a platform (e.g., YouTube, Vimeo, SoundCloud)
44
+
45
+ success, transcript_id = st.transcribe(platform: 'youtube', id: youtube_video_id)
46
+
47
+ Check the status of the transcription process
48
+
49
+ success, status = st.transcript_status(id: transcript_id)
50
+
51
+ Request the completed transcripts
52
+
53
+ success, content = st.transcript(id: transcript_id)
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'speaker_text_api'
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 = SpeakerTextApi.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_api'
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 = SpeakerTextApi.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_api'
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 = SpeakerTextApi.new(config['api_key'])
27
+ success, transcript_id = st.transcribe(platform: 'youtube', id: video_id)
28
+ if success
29
+ puts "Success: Transcript ID is #{transcript_id}"
30
+ else
31
+ puts "Error: #{transcript_id}"
32
+ end
33
+
@@ -0,0 +1,143 @@
1
+ require 'httparty'
2
+ require 'uuidtools'
3
+ require 'json'
4
+
5
+ class SpeakerTextApi
6
+ include HTTParty
7
+ base_uri "https://api.speakertext.com/v1"
8
+ VERSION = '1.0.3'
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 fetch_dfxp_transcript(args)
127
+ args.merge!(format: 'dfxp')
128
+ transcript(args)
129
+ end
130
+
131
+ def transcript_status(args)
132
+ id = args[:id]
133
+
134
+ response = self.class.get("/transcripts/#{id}")
135
+ return [false, "SpeakerText Internal Error"] if response.code==500
136
+
137
+ fields = JSON.parse response.body
138
+
139
+ return [false, fields['message']] if response.code != 200
140
+ return [true, fields['status']]
141
+ end
142
+
143
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speaker_text_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rojesh Shrestha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uuidtools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ description: A gem to automate transcription of audio and video media using the SpeakerText
42
+ service.
43
+ email: rojace2011@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - examples/fetch_transcript.rb
51
+ - examples/speakertext.yaml
52
+ - examples/transcribe_video.rb
53
+ - examples/transcribe_youtube_video.rb
54
+ - lib/speaker_text_api.rb
55
+ homepage: http://github.com/rojesh/speakertext_api
56
+ licenses: []
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.5
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A wrapper gem for speakertext api
78
+ test_files: []
79
+ has_rdoc: