azure_stt 0.1.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.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/ci.yml +33 -0
  4. data/.gitignore +56 -0
  5. data/.rubocop.yml +22 -0
  6. data/CHANGELOG.md +28 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +24 -0
  9. data/Gemfile.lock +141 -0
  10. data/LICENSE +21 -0
  11. data/README.md +129 -0
  12. data/Rakefile +27 -0
  13. data/azure_stt.gemspec +29 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/docs/AzureBatchTranscription.html +301 -0
  17. data/docs/AzureBatchTranscription/Configuration.html +212 -0
  18. data/docs/AzureSTT.html +305 -0
  19. data/docs/AzureSTT/Client.html +1008 -0
  20. data/docs/AzureSTT/Configuration.html +282 -0
  21. data/docs/AzureSTT/Error.html +305 -0
  22. data/docs/AzureSTT/Models.html +135 -0
  23. data/docs/AzureSTT/Models/Base.html +139 -0
  24. data/docs/AzureSTT/Models/CombinedRecognizedPhrases.html +538 -0
  25. data/docs/AzureSTT/Models/File.html +794 -0
  26. data/docs/AzureSTT/Models/RecognizedPhrase.html +769 -0
  27. data/docs/AzureSTT/Models/Report.html +384 -0
  28. data/docs/AzureSTT/Models/Result.html +796 -0
  29. data/docs/AzureSTT/Models/Sentence.html +615 -0
  30. data/docs/AzureSTT/Models/Transcription.html +1415 -0
  31. data/docs/AzureSTT/Models/Word.html +615 -0
  32. data/docs/AzureSTT/NetError.html +159 -0
  33. data/docs/AzureSTT/Parsers.html +128 -0
  34. data/docs/AzureSTT/Parsers/Base.html +404 -0
  35. data/docs/AzureSTT/Parsers/CombinedRecognizedPhrases.html +156 -0
  36. data/docs/AzureSTT/Parsers/File.html +156 -0
  37. data/docs/AzureSTT/Parsers/RecognizedPhrase.html +156 -0
  38. data/docs/AzureSTT/Parsers/Report.html +156 -0
  39. data/docs/AzureSTT/Parsers/Result.html +156 -0
  40. data/docs/AzureSTT/Parsers/Sentence.html +156 -0
  41. data/docs/AzureSTT/Parsers/Transcription.html +156 -0
  42. data/docs/AzureSTT/Parsers/Word.html +156 -0
  43. data/docs/AzureSTT/ServiceError.html +159 -0
  44. data/docs/AzureSTT/Session.html +767 -0
  45. data/docs/AzureSTT/Transcription.html +635 -0
  46. data/docs/AzureSTT/Types.html +116 -0
  47. data/docs/AzureStt_.html +121 -0
  48. data/docs/_index.html +392 -0
  49. data/docs/class_list.html +51 -0
  50. data/docs/css/common.css +1 -0
  51. data/docs/css/full_list.css +58 -0
  52. data/docs/css/style.css +497 -0
  53. data/docs/file.README.html +201 -0
  54. data/docs/file_list.html +56 -0
  55. data/docs/frames.html +17 -0
  56. data/docs/index.html +201 -0
  57. data/docs/js/app.js +314 -0
  58. data/docs/js/full_list.js +216 -0
  59. data/docs/js/jquery.js +4 -0
  60. data/docs/method_list.html +707 -0
  61. data/docs/top-level-namespace.html +110 -0
  62. data/env.sample +2 -0
  63. data/lib/azure_stt.rb +20 -0
  64. data/lib/azure_stt/client.rb +189 -0
  65. data/lib/azure_stt/configuration.rb +28 -0
  66. data/lib/azure_stt/errors.rb +25 -0
  67. data/lib/azure_stt/models.rb +30 -0
  68. data/lib/azure_stt/models/base.rb +27 -0
  69. data/lib/azure_stt/models/combined_recognized_phrases.rb +48 -0
  70. data/lib/azure_stt/models/file.rb +72 -0
  71. data/lib/azure_stt/models/recognized_phrase.rb +70 -0
  72. data/lib/azure_stt/models/report.rb +31 -0
  73. data/lib/azure_stt/models/result.rb +76 -0
  74. data/lib/azure_stt/models/sentence.rb +53 -0
  75. data/lib/azure_stt/models/transcription.rb +185 -0
  76. data/lib/azure_stt/models/word.rb +54 -0
  77. data/lib/azure_stt/parsers.rb +19 -0
  78. data/lib/azure_stt/parsers/base.rb +42 -0
  79. data/lib/azure_stt/parsers/combined_recognized_phrases.rb +28 -0
  80. data/lib/azure_stt/parsers/file.rb +28 -0
  81. data/lib/azure_stt/parsers/recognized_phrase.rb +45 -0
  82. data/lib/azure_stt/parsers/report.rb +25 -0
  83. data/lib/azure_stt/parsers/result.rb +56 -0
  84. data/lib/azure_stt/parsers/sentence.rb +45 -0
  85. data/lib/azure_stt/parsers/transcription.rb +34 -0
  86. data/lib/azure_stt/parsers/word.rb +28 -0
  87. data/lib/azure_stt/session.rb +100 -0
  88. data/lib/azure_stt/version.rb +5 -0
  89. metadata +158 -0
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model class to represent files in our models
7
+ #
8
+ # @see https://francecentral.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/GetTranscriptionFiles/console
9
+ #
10
+ class File < Base
11
+ #
12
+ # The id of the file
13
+ #
14
+ # @!attribute [r] id
15
+ # @return [Types::Coercible::String]
16
+ attribute :id, Types::Coercible::String
17
+
18
+ #
19
+ # The name of the file
20
+ #
21
+ # @!attribute [r] name
22
+ # @return [Types::Coercible::String]
23
+ attribute :name, Types::Coercible::String
24
+
25
+ #
26
+ # The kind of the file. It is useful to determine wether it is a
27
+ # transcription result or a report
28
+ #
29
+ # @!attribute [r] kind
30
+ # @return [Types::Coercible::String]
31
+ attribute :kind, Types::Coercible::String
32
+
33
+ #
34
+ # The properties you specified when you started the transcription
35
+ #
36
+ # @!attribute [r] properties
37
+ # @return [Types::Coercible::Hash]
38
+ attribute :properties, Types::Coercible::Hash
39
+
40
+ #
41
+ # The date the file had been created
42
+ #
43
+ # @!attribute [r] created_date_time
44
+ # @return [Types::Date]
45
+ attribute :created_date_time, Types::Date
46
+
47
+ #
48
+ # The url where you will be able to find the file. This url is valid only
49
+ # for a period of time.
50
+ #
51
+ # @!attribute [r] content_url
52
+ # @return [Types::Coercible::String]
53
+ attribute :content_url, Types::Coercible::String
54
+
55
+ #
56
+ # The client used to interrogate the API to get the content of the file
57
+ #
58
+ # @!attribute [r] client
59
+ # @return [AzureSTT::Client]
60
+ attribute :client, Types.Instance(AzureSTT::Client)
61
+
62
+ #
63
+ # Returns the result of the request to the file with the url content_url
64
+ #
65
+ # @return [Hash]
66
+ #
67
+ def content
68
+ client.get_file(content_url)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model class to store a recognized phrase from the results file
7
+ #
8
+ class RecognizedPhrase < Base
9
+ #
10
+ # The status of the recognition for this phrase
11
+ #
12
+ # @!attribute [r] recognition_status
13
+ # @return [Types::Coercible::String]
14
+ attribute :recognition_status, Types::Coercible::String
15
+
16
+ #
17
+ # The channel of the phrase. The API supports only two channels, so
18
+ # it is 0 or 1
19
+ #
20
+ # @!attribute [r] channel
21
+ # @return [Types::Coercible::Integer]
22
+ attribute :channel, Types::Coercible::Integer
23
+
24
+ #
25
+ # The speaker. The API supports only two speakers, so it is 0 or 1
26
+ #
27
+ # @!attribute [r] speaker
28
+ # @return [Types::Coercible::Integer]
29
+ attribute? :speaker, Types::Coercible::Integer
30
+
31
+ #
32
+ # The offset of the phrase in the audio. Ex: 'PT0.13S' means that the
33
+ # phrase begins at 13 seconds on the audio file
34
+ #
35
+ # @!attribute [r] offset
36
+ # @return [Types::Coercible::String]
37
+ attribute? :offset, Types::Coercible::String
38
+
39
+ #
40
+ # The duration of the phrase. Ex: 'PT0.13S' means that the phrase lasts 13
41
+ # seconds
42
+ #
43
+ # @!attribute [r] duration
44
+ # @return [Types::Coercible::String]
45
+ attribute? :duration, Types::Coercible::String
46
+
47
+ #
48
+ # The offset of the phrase in the audio in ticks.
49
+ #
50
+ # @!attribute [r] offset_in_ticks
51
+ # @return [Types::Coercible::Integer]
52
+ attribute? :offset_in_ticks, Types::Coercible::Integer
53
+
54
+ #
55
+ # The duration of the phrase in ticks
56
+ #
57
+ # @!attribute [r] duration_in_ticks
58
+ # @return [Types::Coercible::Integer]
59
+ attribute? :duration_in_ticks, Types::Coercible::Integer
60
+
61
+ #
62
+ # The sentences the API recognized. The first is the sentence with the
63
+ # highest confidence.
64
+ #
65
+ # @!attribute [r] n_best
66
+ # @return [Types::Array.of(Sentence)]
67
+ attribute :n_best, Types::Array.of(Sentence).default([].freeze)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model class for reports from a transcription.
7
+ #
8
+ class Report < Base
9
+ #
10
+ # The number of audio files that had been successsfully transcripted
11
+ #
12
+ # @!attribute [r] successful_transcriptions_count
13
+ # @return [Types::Coercible::Integer]
14
+ attribute :successful_transcriptions_count, Types::Coercible::Integer
15
+
16
+ #
17
+ # The number of audio files that have failed
18
+ #
19
+ # @!attribute [r] failed_transcriptions_count
20
+ # @return [Types::Coercible::Integer]
21
+ attribute :failed_transcriptions_count, Types::Coercible::Integer
22
+
23
+ #
24
+ # The details
25
+ #
26
+ # @!attribute [r] details
27
+ # @return [Types::Array.of(Types::Hash)]
28
+ attribute :details, Types::Array.of(Types::Hash).default([].freeze)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model class for the results of a transcription when the transcription is
7
+ # successful
8
+ #
9
+ class Result < Base
10
+ #
11
+ # The audio file source
12
+ #
13
+ # @!attribute [r] source
14
+ # @return [Types::Coercible::String]
15
+ attribute :source, Types::Coercible::String
16
+
17
+ #
18
+ # The creation date of the result file
19
+ #
20
+ # @!attribute [r] timestamp
21
+ # @return [Types::Date]
22
+ attribute :timestamp, Types::Date
23
+
24
+ #
25
+ # The duration of the audio in ticks
26
+ #
27
+ # @!attribute [r] duration_in_ticks
28
+ # @return [Types::Coercible::Integer]
29
+ attribute :duration_in_ticks, Types::Coercible::Integer
30
+
31
+ #
32
+ # The duration of the audio in a String format
33
+ #
34
+ # @!attribute [r] duration
35
+ # @return [Types::Coercible::String]
36
+ attribute :duration, Types::Coercible::String
37
+
38
+ #
39
+ # The transcript. It seems that the API generates one
40
+ # 'combinedRecognizedPhrase per channel.
41
+ #
42
+ # @!attribute [r] combined_recognized_phrases
43
+ # @return [Types::Array.of(CombinedRecognizedPhrases)]
44
+ attribute :combined_recognized_phrases,
45
+ Types::Array.of(CombinedRecognizedPhrases).default([].freeze)
46
+
47
+ #
48
+ # The phrases that have been recognized from by the transcription
49
+ #
50
+ # @!attribute [r] recognized_phrases
51
+ # @return [Types::Array.of(RecognizedPhrases)]
52
+ attribute :recognized_phrases,
53
+ Types::Array.of(RecognizedPhrase).default([].freeze)
54
+
55
+ #
56
+ # The display field of the first CombinedRecognizedPhrases
57
+ #
58
+ # @return [String]
59
+ #
60
+ def text
61
+ combined_recognized_phrases.first.transcript
62
+ end
63
+
64
+ #
65
+ # Get all the best Models::Sentence of a result.
66
+ #
67
+ # @return [Array[Models::Sentence]]
68
+ #
69
+ def sentences
70
+ recognized_phrases.map do |recognized_phrase|
71
+ recognized_phrase.n_best.first
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model to describe a sentence. A sentence is inside a nBest of a recognizedPhrase
7
+ #
8
+ class Sentence < Base
9
+ #
10
+ # The confidence score of the transcripted sentence.
11
+ #
12
+ # @!attribute [r] confidence
13
+ # @return [Types::Coercible::Float]
14
+ attribute :confidence, Types::Coercible::Float
15
+
16
+ #
17
+ # The lexical field
18
+ #
19
+ # @!attribute [r] lexical
20
+ # @return [Types::Coercible::String]
21
+ attribute :lexical, Types::Coercible::String
22
+
23
+ #
24
+ # The itn field
25
+ #
26
+ # @!attribute [r] itn
27
+ # @return [Types::Coercible::String]
28
+ attribute :itn, Types::Coercible::String
29
+
30
+ #
31
+ # The maskedITN field
32
+ #
33
+ # @!attribute [r] masked_itn
34
+ # @return [Types::Coercible::String]
35
+ attribute :masked_itn, Types::Coercible::String
36
+
37
+ #
38
+ # The display field. Displays the text with the format you specified in
39
+ # the paramters of the transcription.
40
+ #
41
+ # @!attribute [r] transcript
42
+ # @return [Types::Coercible::String]
43
+ attribute :transcript, Types::Coercible::String
44
+
45
+ #
46
+ # The words recognized in the sentence.
47
+ #
48
+ # @!attribute [r] words
49
+ # @return [Types::Array.of(Word)]
50
+ attribute? :words, Types::Array.of(Word).default([].freeze)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AzureSTT
4
+ module Models
5
+ #
6
+ # Model for a transcription. Contains the results and static methods to
7
+ # create and retrieve the transcriptions.
8
+ #
9
+ class Transcription < Base
10
+ #
11
+ # The id of the transcription
12
+ #
13
+ # @!attribute [r] id
14
+ # @return [Types::Coercible::String]
15
+ attribute :id, Types::Coercible::String
16
+
17
+ #
18
+ # The model url of the transcription
19
+ #
20
+ # @!attribute [r] model
21
+ # @return [Types::Coercible::String]
22
+ attribute :model, Types::Coercible::String
23
+
24
+ #
25
+ # The properties of the transcription
26
+ #
27
+ # @!attribute [r] properties
28
+ # @return [Types::Hash]
29
+ attribute :properties, Types::Hash
30
+
31
+ #
32
+ # The links for the transcription (usually just a link to the files route)
33
+ #
34
+ # @!attribute [r] links
35
+ # @return [Types::Hash]
36
+ attribute :links, Types::Hash
37
+
38
+ #
39
+ # The last date the transcription has been updated
40
+ #
41
+ # @!attribute [r] last_action_date_time
42
+ # @return [Types::Date]
43
+ attribute :last_action_date_time, Types::Date
44
+
45
+ #
46
+ # The date the transcription has been created
47
+ #
48
+ # @!attribute [r] created_date_time
49
+ # @return [Types::Date]
50
+ attribute :created_date_time, Types::Date
51
+
52
+ #
53
+ # The status of the transcription
54
+ #
55
+ # @!attribute [r] status
56
+ # @return [Types::Coercible::String]
57
+ attribute :status, Types::Coercible::String
58
+
59
+ #
60
+ # The locale of the transcription. Example: 'en-US'
61
+ #
62
+ # @!attribute [r] locale
63
+ # @return [Types::Coercible::String]
64
+ attribute :locale, Types::Coercible::String
65
+
66
+ #
67
+ # The displayName of the transcription, not unique
68
+ #
69
+ # @!attribute [r] display_name
70
+ # @return [Types::Coercible::String]
71
+ attribute :display_name, Types::Coercible::String
72
+
73
+ #
74
+ # The transcription's files that can be retrieve
75
+ #
76
+ # @!attribute [r] files
77
+ # @return [Types::Array.of(File)]
78
+ attribute? :files, Types::Array.of(File).default([].freeze)
79
+
80
+ #
81
+ # The client used to interrogate the API
82
+ #
83
+ # @!attribute [r] client
84
+ # @return [AzureSTT::Client]
85
+ attribute :client, Types.Instance(AzureSTT::Client)
86
+
87
+ #
88
+ # Is the process still running ?
89
+ #
90
+ # @return [Boolean]
91
+ #
92
+ def running?
93
+ status == 'Running'
94
+ end
95
+
96
+ #
97
+ # Is the status is failed ?
98
+ #
99
+ # @return [Boolean]
100
+ #
101
+ def failed?
102
+ status == 'Failed'
103
+ end
104
+
105
+ #
106
+ # Has the process succeeded ?
107
+ #
108
+ # @return [Boolean]
109
+ #
110
+ def succeeded?
111
+ status == 'Succeeded'
112
+ end
113
+
114
+ #
115
+ # Is the process finished ? (Succeeded or failed)
116
+ #
117
+ # @return [Boolean]
118
+ #
119
+ def finished?
120
+ succeeded? || failed?
121
+ end
122
+
123
+ #
124
+ # Get the report of a transcription from transcriptions/id/files route
125
+ #
126
+ # @see https://centralus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/GetTranscriptionFiles/console
127
+ #
128
+ # @return [Models::Report]
129
+ #
130
+ def report
131
+ @report ||= retrieve_report
132
+ end
133
+
134
+ #
135
+ # Get the results of a transcription. The results are the files containing
136
+ # the speech-to-text. As a transcription process can have multiple files,
137
+ # the results are in an Array.
138
+ #
139
+ # @return [Array[Models::Result]]
140
+ #
141
+ def results
142
+ @results ||= retrieve_results
143
+ end
144
+
145
+ private
146
+
147
+ #
148
+ # All the files of a transcription
149
+ #
150
+ # @return [Array[File]] The files of the transcription
151
+ #
152
+ def files
153
+ @files ||= retrieve_files
154
+ end
155
+
156
+ #
157
+ # Interrogate the API to retrieve the files
158
+ #
159
+ # @return [Array[Files]] The files of the transcription
160
+ #
161
+ def retrieve_files
162
+ files_array = client.get_transcription_files(id)
163
+ files_array.map do |file_hash|
164
+ Models::File.new(
165
+ Parsers::File.new(file_hash).attributes.merge({ client: client })
166
+ )
167
+ end
168
+ end
169
+
170
+ def retrieve_report
171
+ report_file = files.find { |f| f.kind == 'TranscriptionReport' }
172
+ file_hash = report_file.content
173
+ Models::Report.new(Parsers::Report.new(file_hash).attributes)
174
+ end
175
+
176
+ def retrieve_results
177
+ results_files = files.select { |f| f.kind == 'Transcription' }
178
+ results_files.map do |result_file|
179
+ result_hash = result_file.content
180
+ Models::Result.new(Parsers::Result.new(result_hash).attributes)
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end