speech_to_text 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +98 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/speech_to_text.rb +9 -0
- data/lib/speech_to_text/deepspeech.rb +44 -0
- data/lib/speech_to_text/google.rb +82 -0
- data/lib/speech_to_text/ibm.rb +56 -0
- data/lib/speech_to_text/util.rb +90 -0
- data/lib/speech_to_text/version.rb +3 -0
- data/speech_to_text.gemspec +44 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8773539fa2b12c95e93b39fee40555e742ebd20db3ee643b8798c4692b38f6cb
|
4
|
+
data.tar.gz: a8ed35f48b5558b5ff97952d230e7fc4b27c64a2b6aeb0d0e0cd18ef4cd6f3f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00ca5c7aedd8be006ab6b39dc3a1512e612c4a6c1f7bd0c1439fc256f67a8a4a889e67fcfe58741c18ec12c8c2441e03f895079b7291a6ce8415b45ada87a644
|
7
|
+
data.tar.gz: 8b27381c72ff91de50afa1ff1f89b761f099b7c8ea23a79528e4fb7c445ba745652143a42962158fc5e2d1e7c8e3d5e12347f9613309b4af0822dcfee998f36a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
speech_to_text (0.1.0)
|
5
|
+
google-cloud-speech (= 0.35.0)
|
6
|
+
google-cloud-storage (= 1.18.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
declarative (0.0.10)
|
14
|
+
declarative-option (0.1.0)
|
15
|
+
digest-crc (0.4.1)
|
16
|
+
faraday (0.15.4)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
google-api-client (0.30.2)
|
19
|
+
addressable (~> 2.5, >= 2.5.1)
|
20
|
+
googleauth (>= 0.5, < 0.10.0)
|
21
|
+
httpclient (>= 2.8.1, < 3.0)
|
22
|
+
mini_mime (~> 1.0)
|
23
|
+
representable (~> 3.0)
|
24
|
+
retriable (>= 2.0, < 4.0)
|
25
|
+
signet (~> 0.10)
|
26
|
+
google-cloud-core (1.3.0)
|
27
|
+
google-cloud-env (~> 1.0)
|
28
|
+
google-cloud-env (1.1.0)
|
29
|
+
faraday (~> 0.11)
|
30
|
+
google-cloud-speech (0.35.0)
|
31
|
+
google-gax (~> 1.3)
|
32
|
+
google-cloud-storage (1.18.2)
|
33
|
+
addressable (~> 2.5)
|
34
|
+
digest-crc (~> 0.4)
|
35
|
+
google-api-client (~> 0.26)
|
36
|
+
google-cloud-core (~> 1.2)
|
37
|
+
googleauth (>= 0.6.2, < 0.10.0)
|
38
|
+
mime-types (~> 3.0)
|
39
|
+
google-gax (1.6.3)
|
40
|
+
google-protobuf (~> 3.2)
|
41
|
+
googleapis-common-protos (>= 1.3.5, < 2.0)
|
42
|
+
googleauth (>= 0.6.2, < 0.10.0)
|
43
|
+
grpc (>= 1.7.2, < 2.0)
|
44
|
+
rly (~> 0.2.3)
|
45
|
+
google-protobuf (3.8.0-x64-mingw32)
|
46
|
+
googleapis-common-protos (1.3.9)
|
47
|
+
google-protobuf (~> 3.0)
|
48
|
+
googleapis-common-protos-types (~> 1.0)
|
49
|
+
grpc (~> 1.0)
|
50
|
+
googleapis-common-protos-types (1.0.4)
|
51
|
+
google-protobuf (~> 3.0)
|
52
|
+
googleauth (0.8.1)
|
53
|
+
faraday (~> 0.12)
|
54
|
+
jwt (>= 1.4, < 3.0)
|
55
|
+
memoist (~> 0.16)
|
56
|
+
multi_json (~> 1.11)
|
57
|
+
os (>= 0.9, < 2.0)
|
58
|
+
signet (~> 0.7)
|
59
|
+
grpc (1.21.0-x64-mingw32)
|
60
|
+
google-protobuf (~> 3.7)
|
61
|
+
googleapis-common-protos-types (~> 1.0)
|
62
|
+
httpclient (2.8.3)
|
63
|
+
jwt (2.2.1)
|
64
|
+
memoist (0.16.0)
|
65
|
+
mime-types (3.2.2)
|
66
|
+
mime-types-data (~> 3.2015)
|
67
|
+
mime-types-data (3.2019.0331)
|
68
|
+
mini_mime (1.0.1)
|
69
|
+
multi_json (1.13.1)
|
70
|
+
multipart-post (2.1.1)
|
71
|
+
os (1.0.1)
|
72
|
+
public_suffix (3.1.0)
|
73
|
+
rake (10.5.0)
|
74
|
+
representable (3.0.4)
|
75
|
+
declarative (< 0.1.0)
|
76
|
+
declarative-option (< 0.2.0)
|
77
|
+
uber (< 0.2.0)
|
78
|
+
retriable (3.1.2)
|
79
|
+
rly (0.2.3)
|
80
|
+
signet (0.11.0)
|
81
|
+
addressable (~> 2.3)
|
82
|
+
faraday (~> 0.9)
|
83
|
+
jwt (>= 1.5, < 3.0)
|
84
|
+
multi_json (~> 1.10)
|
85
|
+
uber (0.1.0)
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
x64-mingw32
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
bundler (~> 2.0)
|
92
|
+
google-cloud-speech
|
93
|
+
google-cloud-storage
|
94
|
+
rake (~> 10.0)
|
95
|
+
speech_to_text!
|
96
|
+
|
97
|
+
BUNDLED WITH
|
98
|
+
2.0.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 BigBlueButton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Richard Alam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# SpeechToText
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/speech_to_text`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'speech_to_text'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install speech_to_text
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
BigBlueButton provides various captions services.
|
24
|
+
Use following command to access the different services.
|
25
|
+
```ruby
|
26
|
+
SpeechToText::BBBIbmCaptions.ibm_speech_to_text(<published_files_path>,<recordID>,<apikey>)
|
27
|
+
SpeechToText::BBBGoogleCaptions.google_speech_to_text(<published_files>,<recordID>,<auth_file>,<bucket_name>)
|
28
|
+
```
|
29
|
+
|
30
|
+
NOTE:
|
31
|
+
you can use this gemfile only if you have following directory structure.
|
32
|
+
<published_files_path>/<recordID>/video where <published_files_path> could be any path and <recordID> should be inside the <published_files_path>.
|
33
|
+
Your <recordID> folder will contain "video" folder which has video.mp4 or video.webm file inside "video" folder.
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
NOTE : After your changes execute this commands
|
42
|
+
1. Build your gem file : 'gem build speech_to_text.gemspec'
|
43
|
+
2. Install your gem file : 'gem install speech_to_text-0.1.0.gem' //replace the version number
|
44
|
+
3. 'bundle install' //optional command
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/speech_to_text.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "speech_to_text"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Set encoding to utf-8
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
5
|
+
#
|
6
|
+
# Copyright (c) 2019 BigBlueButton Inc. and by respective authors (see below).
|
7
|
+
#
|
8
|
+
require_relative "util.rb"
|
9
|
+
|
10
|
+
module SpeechToText
|
11
|
+
module BBBDeepspeech
|
12
|
+
include Util
|
13
|
+
|
14
|
+
def create_deepspeech_array(data)
|
15
|
+
i=0
|
16
|
+
myarray = []
|
17
|
+
while i<data["words"].length
|
18
|
+
myarray.push(data["words"][i]["time"].to_f)
|
19
|
+
if i == data["words"].length - 1
|
20
|
+
endtime = data["file"]["duration"].to_f
|
21
|
+
else
|
22
|
+
endtime = data["words"][i+1]["time"].to_f
|
23
|
+
end
|
24
|
+
myarray.push(endtime)
|
25
|
+
myarray.push(data["words"][i]["word"])
|
26
|
+
i = i+1
|
27
|
+
end
|
28
|
+
return myarray
|
29
|
+
end
|
30
|
+
|
31
|
+
def BBBDeepspeechCaptions(published_files, recordID)
|
32
|
+
require 'json'
|
33
|
+
video_to_audio_command = "ffmpeg -i #{published_files}/#{recordID}/video/video.mp4 #{published_files}/#{recordID}/#{recordID}.wav"
|
34
|
+
system(video_to_audio_command)
|
35
|
+
jsonfile_path = "#{published_files}/#{recordID}/#{recordID}.json"
|
36
|
+
deepspeech_command = "./deepspeech --model models/output_graph.pbmm --alphabet models/alphabet.txt --lm models/lm.binary --trie models/trie -e --audio #{published_files}/#{recordID}/#{recordID}.wav > #{jsonfile_path}"
|
37
|
+
system("#{deepspeech_command}")
|
38
|
+
file = File.open(jsonfile_path,"r")
|
39
|
+
data = JSON.load(file)
|
40
|
+
deepspeech_array = create_deepspeech_array(data)
|
41
|
+
Util.write_to_webvtt deepspeech_array
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Set encoding to utf-8
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#
|
5
|
+
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 BigBlueButton Inc. and by respective authors (see below).
|
8
|
+
#
|
9
|
+
require_relative "util.rb"
|
10
|
+
|
11
|
+
module SpeechToText
|
12
|
+
module BBBGoogleCaptions
|
13
|
+
require "google/cloud/speech"
|
14
|
+
require "google/cloud/storage"
|
15
|
+
include Util
|
16
|
+
#create an array with the start time, stop time and words
|
17
|
+
def self.create_array_google results
|
18
|
+
data_array = []
|
19
|
+
results.each do |result|
|
20
|
+
result.alternatives.each do |alternative|
|
21
|
+
alternative.words.each_with_index do |word, i|
|
22
|
+
start_time = word.start_time.seconds + word.start_time.nanos/1000000000.0
|
23
|
+
end_time = word.end_time.seconds + word.end_time.nanos/1000000000.0
|
24
|
+
|
25
|
+
data_array.push(start_time)
|
26
|
+
data_array.push(end_time)
|
27
|
+
data_array.push(word.word)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return data_array
|
32
|
+
end
|
33
|
+
|
34
|
+
#uploads audio file to a google bucket
|
35
|
+
def self.google_storage(published_files,recordID,bucket_name)
|
36
|
+
storage = Google::Cloud::Storage.new project_id: bucket_name
|
37
|
+
bucket = storage.bucket bucket_name
|
38
|
+
file = bucket.create_file "#{published_files}/#{recordID}/#{recordID}.flac","#{recordID}.flac"
|
39
|
+
return file
|
40
|
+
end
|
41
|
+
|
42
|
+
#return the results from google speech
|
43
|
+
def self.google_transcription(recordID,bucket_name)
|
44
|
+
# Instantiates a client
|
45
|
+
speech = Google::Cloud::Speech.new
|
46
|
+
|
47
|
+
# The audio file's encoding and sample rate
|
48
|
+
config = { encoding: :FLAC,
|
49
|
+
sample_rate_hertz: 16000,#transcoded_movie.audio_sample_rate,
|
50
|
+
language_code: "en-US",
|
51
|
+
enable_word_time_offsets: true }
|
52
|
+
audio = { #content: audio_file #using local audio file
|
53
|
+
#uri: "gs://bbb-accessibility/video.FLAC" #static bucket file usage
|
54
|
+
uri: "gs://#{bucket_name}/#{recordID}.flac" #using the now uploaded audio file from the bucket
|
55
|
+
}
|
56
|
+
|
57
|
+
# Detects speech in the audio file
|
58
|
+
operation = speech.long_running_recognize config, audio
|
59
|
+
|
60
|
+
#puts "Operation started"
|
61
|
+
|
62
|
+
operation.wait_until_done!
|
63
|
+
|
64
|
+
raise operation.results.message if operation.error?
|
65
|
+
|
66
|
+
results = operation.response.results
|
67
|
+
return results
|
68
|
+
end
|
69
|
+
|
70
|
+
#Google-speech-to-text function
|
71
|
+
def self.google_speech_to_text(published_files,recordID,auth_file,bucket_name)
|
72
|
+
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = auth_file
|
73
|
+
Util.video_to_audio(published_files,recordID)
|
74
|
+
file = google_storage(published_files,recordID,bucket_name)
|
75
|
+
results = google_transcription(recordID,bucket_name)
|
76
|
+
|
77
|
+
data_array = create_array_google(results)
|
78
|
+
Util.write_to_webvtt(published_files,recordID,data_array)
|
79
|
+
file.delete
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Set encoding to utf-8
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
5
|
+
#
|
6
|
+
# Copyright (c) 2019 BigBlueButton Inc. and by respective authors (see below).
|
7
|
+
#
|
8
|
+
require_relative "util.rb"
|
9
|
+
|
10
|
+
module SpeechToText
|
11
|
+
module BBBIbmCaptions
|
12
|
+
include Util
|
13
|
+
#create array from json file
|
14
|
+
def self.create_array_watson data
|
15
|
+
k = 0
|
16
|
+
myarray = []
|
17
|
+
while k!= data["results"].length
|
18
|
+
j = 0
|
19
|
+
while j!= data["results"][k]["alternatives"].length
|
20
|
+
i = 0
|
21
|
+
while i!= data["results"][k]["alternatives"][j]["timestamps"].length
|
22
|
+
first = data["results"][k]["alternatives"][j]["timestamps"][i][1]
|
23
|
+
last = data["results"][k]["alternatives"][j]["timestamps"][i][2]
|
24
|
+
transcript = data["results"][k]["alternatives"][j]["timestamps"][i][0]
|
25
|
+
|
26
|
+
if transcript.include? "%HESITATION"
|
27
|
+
transcript["%HESITATION"] = ""
|
28
|
+
end
|
29
|
+
myarray.push(first)
|
30
|
+
myarray.push(last)
|
31
|
+
myarray.push(transcript)
|
32
|
+
i+=1
|
33
|
+
end
|
34
|
+
confidence = data["results"][k]["alternatives"][j]["confidence"]
|
35
|
+
myarray[myarray.length-2] = myarray[myarray.length-2] + confidence
|
36
|
+
j+=1
|
37
|
+
end
|
38
|
+
k+=1
|
39
|
+
end
|
40
|
+
return myarray
|
41
|
+
end
|
42
|
+
|
43
|
+
#ibm speech to text main function
|
44
|
+
def self.ibm_speech_to_text(published_files,recordID,apikey)
|
45
|
+
require 'json'
|
46
|
+
jsonfile_path = "#{published_files}/#{recordID}/audio.json"
|
47
|
+
Util.video_to_audio(published_files,recordID)
|
48
|
+
watson_command = "curl -X POST -u \"apikey:#{apikey}\" --header \"Content-Type: audio/flac\" --data-binary @#{published_files}/#{recordID}/#{recordID}.flac \"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?timestamps=true\" > #{jsonfile_path}"
|
49
|
+
system("#{watson_command}")
|
50
|
+
out = File.open(jsonfile_path, "r")
|
51
|
+
data = JSON.load out
|
52
|
+
myarray = create_array_watson data
|
53
|
+
Util.write_to_webvtt(published_files,recordID,myarray)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Set encoding to utf-8
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
#
|
5
|
+
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
6
|
+
#
|
7
|
+
# Copyright (c) 2019 BigBlueButton Inc. and by respective authors (see below).
|
8
|
+
#
|
9
|
+
|
10
|
+
module SpeechToText
|
11
|
+
module Util
|
12
|
+
#function to convert the time to a timestamp
|
13
|
+
def self.seconds_to_timestamp number
|
14
|
+
ss = number
|
15
|
+
mm = ss / 60
|
16
|
+
hh = (number/3600).floor
|
17
|
+
number = number % 3600
|
18
|
+
mm = (number / 60).floor
|
19
|
+
ss = (number % 60).round(3)
|
20
|
+
if ss < 10
|
21
|
+
ss = "0#{ss.to_s}"
|
22
|
+
end
|
23
|
+
parts = ss.to_s.split(".")
|
24
|
+
if parts.length > 1
|
25
|
+
1.upto (3-parts[1].length) {parts[1] = parts[1].concat("0")}
|
26
|
+
ss = "#{parts[0]}.#{parts[1]}"
|
27
|
+
else
|
28
|
+
ss = parts[0].concat(".000")
|
29
|
+
end
|
30
|
+
if mm < 10
|
31
|
+
mm = "0#{mm.to_s}"
|
32
|
+
end
|
33
|
+
if hh < 10
|
34
|
+
hh = "0#{hh.to_s}"
|
35
|
+
end
|
36
|
+
return "#{hh}:#{mm}:#{ss}"
|
37
|
+
end
|
38
|
+
|
39
|
+
#create and write the webvtt file
|
40
|
+
def self.write_to_webvtt(published_files,recordID,myarray)
|
41
|
+
|
42
|
+
filename = "#{published_files}/#{recordID}/caption_en_US.vtt"
|
43
|
+
file = File.open(filename,"w")
|
44
|
+
file.puts ("WEBVTT\n\n")
|
45
|
+
|
46
|
+
i=0
|
47
|
+
|
48
|
+
while(i<myarray.length)
|
49
|
+
|
50
|
+
file.puts i/30 + 1
|
51
|
+
if i+28 < myarray.length
|
52
|
+
file.puts "#{seconds_to_timestamp myarray[i]} --> #{seconds_to_timestamp myarray[i+28]}"
|
53
|
+
file.puts "#{myarray[i+2]} #{myarray[i+5]} #{myarray[i+8]} #{myarray[i+11]} #{myarray[i+14]}"
|
54
|
+
file.puts "#{myarray[i+17]} #{myarray[i+20]} #{myarray[i+23]} #{myarray[i+26]} #{myarray[i+29]}\n\n"
|
55
|
+
else
|
56
|
+
remainder = myarray.length - i
|
57
|
+
file.puts "#{seconds_to_timestamp myarray[i]} --> #{seconds_to_timestamp myarray[myarray.length-2]}"
|
58
|
+
count = 0
|
59
|
+
flag = true
|
60
|
+
while (count < remainder )
|
61
|
+
file.print "#{myarray[i+2]} "
|
62
|
+
if flag
|
63
|
+
if count > 9
|
64
|
+
file.print "\n"
|
65
|
+
flag = false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
i+=3
|
69
|
+
count+=3
|
70
|
+
end
|
71
|
+
end
|
72
|
+
i = i + 30
|
73
|
+
end
|
74
|
+
|
75
|
+
file.close
|
76
|
+
|
77
|
+
#system(scp -v "#{$published_files}/caption_en_US.vtt" "#{$captions_inbox_path}/#{$meeting_id}-#{$current_time}-track.txt")
|
78
|
+
captions_file_name = "#{published_files}/captions.json"
|
79
|
+
captions_file = File.open(captions_file_name,"w")
|
80
|
+
captions_file.puts ("[{\"localeName\": \"English (United States)\", \"locale\": \"en_US\"}]")
|
81
|
+
end
|
82
|
+
|
83
|
+
#def video_to_audio
|
84
|
+
def self.video_to_audio(published_files,recordID)
|
85
|
+
video_to_audio_command = "ffmpeg -i #{published_files}/#{recordID}/video/video.mp4 -ac 1 -ar 16000 #{published_files}/#{recordID}/#{recordID}.flac"
|
86
|
+
system("#{video_to_audio_command}")
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "speech_to_text/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "speech_to_text"
|
8
|
+
spec.version = SpeechToText::VERSION
|
9
|
+
spec.authors = ["Richard Alam"]
|
10
|
+
spec.email = ["ritzalam@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{speech to text using different services}
|
13
|
+
#spec.description = %q{speech to text using google and ibm}
|
14
|
+
spec.homepage = "https://github.com/bigbluebutton/speech_to_text"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
=begin
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata["allowed_push_host"] = "Set to 'http://droplet-949.meetbbb.com'"
|
22
|
+
|
23
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
24
|
+
spec.metadata["source_code_uri"] = "https://github.com/bigbluebutton/speech_to_text.git"
|
25
|
+
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
26
|
+
else
|
27
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
28
|
+
"public gem pushes."
|
29
|
+
end
|
30
|
+
=end
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = "exe"
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
41
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
42
|
+
spec.add_dependency "google-cloud-storage", "1.18.2"
|
43
|
+
spec.add_dependency "google-cloud-speech", "0.35.0"
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: speech_to_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Alam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google-cloud-storage
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.18.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.18.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: google-cloud-speech
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.35.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.35.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ritzalam@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/speech_to_text.rb
|
86
|
+
- lib/speech_to_text/deepspeech.rb
|
87
|
+
- lib/speech_to_text/google.rb
|
88
|
+
- lib/speech_to_text/ibm.rb
|
89
|
+
- lib/speech_to_text/util.rb
|
90
|
+
- lib/speech_to_text/version.rb
|
91
|
+
- speech_to_text.gemspec
|
92
|
+
homepage: https://github.com/bigbluebutton/speech_to_text
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.6.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: speech to text using different services
|
116
|
+
test_files: []
|