omniai-openai 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f35b8f18f1fed4fc62a4d69d1ec9d94b7b93dfe6d7110e9f64369625cafd8702
4
- data.tar.gz: 746528fa3065f9f843bafb9b82946dda6d57bb121b81bbf6a8f4c43e72e1888e
3
+ metadata.gz: 8fa0f1acc820456282d48d42e9bc1154f8aa9b83fe9fa86817e1d3446a8cd31d
4
+ data.tar.gz: cd4c84c579985a17c96edadcb91324b545035bf170fb20c3172855e13e83586c
5
5
  SHA512:
6
- metadata.gz: 4a11987f0c6dceeed121166820240c9c878ddc7f88b7c2cf2598c5f14ed5cdc1d6730d3463396f4c56b38f37d7ac4d983b7af461afd00c58db613a58b887d075
7
- data.tar.gz: 129bd67690492743d3945fc15da22d5b9f4ec1bc384c56d8dcd2d60d1fd0419f802c6b804cbf154efdd4828d5e42220a30f890d58c08f9aaa634c1c8ba8bfa20
6
+ metadata.gz: c4583c5da031c749e56b6ec2bbcf59daaebe8f873c5fe9a9cbdfdfb67acf8d8eabc798a754fe5e2784fd73495bb91181deb3e323d00e0e84d962ff86624192a5
7
+ data.tar.gz: fcf7612d1f7361697820a3e14cf5558fe83fb096b1154a5c3a67c3c6c64823d230e1c1d029252ee91fa0e9cd26bbba398fc18612189171db891d47a830536266
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # OmniAI::OpenAI
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/ksylvest/omniai-openai.svg?style=svg)](https://circleci.com/gh/ksylvest/omniai-openai)
4
+
3
5
  An OpenAI implementation of the [OmniAI](https://github.com/ksylvest/omniai) APIs.
4
6
 
5
7
  ## Installation
@@ -169,3 +171,63 @@ transcription.text
169
171
  ```
170
172
 
171
173
  [OpenAI API Reference `temperature`](https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-temperature)
174
+
175
+ ### Speak
176
+
177
+ Speech can be generated by passing text with a block:
178
+
179
+ ```ruby
180
+ File.open('example.ogg', 'wb') do |file|
181
+ client.speak('How can a clam cram in a clean cream can?') do |chunk|
182
+ file << chunk
183
+ end
184
+ end
185
+ ```
186
+
187
+ If a block is not provided then a tempfile is returned:
188
+
189
+ ```ruby
190
+ tempfile = client.speak('Can you can a can as a canner can can a can?')
191
+ tempfile.close
192
+ tempfile.unlink
193
+ ```
194
+
195
+ #### Voice
196
+
197
+ `voice` is optional and must be one of the supported voices:
198
+
199
+ ```ruby
200
+ client.speak('She sells seashells by the seashore.', voice: OmniAI::OpenAI::Speak::Voice::SHIMMER)
201
+ ```
202
+
203
+ [OpenAI API Reference `voice`](https://platform.openai.com/docs/api-reference/audio/createSpeech#audio-createspeech-voice)
204
+
205
+ #### Model
206
+
207
+ `model` is optional and must be either `tts-1` or `tts-1-hd` (default):
208
+
209
+ ```ruby
210
+ client.speak('I saw a kitten eating chicken in the kitchen.', format: OmniAI::OpenAI::Speak::Model::TTS_1)
211
+ ```
212
+
213
+ [OpenAI API Refernce `model`](https://platform.openai.com/docs/api-reference/audio/createSpeech#audio-createspeech-model)
214
+
215
+ #### Speed
216
+
217
+ `speed` is optional and must be between 0.25 and 0.40:
218
+
219
+ ```ruby
220
+ client.speak('How much wood would a woodchuck chuck if a woodchuck could chuck wood?', speed: 4.0)
221
+ ```
222
+
223
+ [OmniAI API Reference `speed`](https://platform.openai.com/docs/api-reference/audio/createSpeech#audio-createspeech-speed)
224
+
225
+ #### Format
226
+
227
+ `format` is optional and supports `MP3` (default), `OPUS`, `AAC`, `FLAC`, `WAV` or `PCM`:
228
+
229
+ ```ruby
230
+ client.speak('A pessemistic pest exists amidst us.', format: OmniAI::OpenAI::Speak::Format::FLAC)
231
+ ```
232
+
233
+ [OpenAI API Reference `format`](https://platform.openai.com/docs/api-reference/audio/createSpeech#audio-createspeech-response_format)
@@ -78,6 +78,27 @@ module OmniAI
78
78
  def transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil)
79
79
  Transcribe.process!(path, model:, language:, prompt:, temperature:, format:, client: self)
80
80
  end
81
+
82
+ # @raise [OmniAI::Error]
83
+ #
84
+ # @param input [String] required
85
+ # @param model [String] optional
86
+ # @param voice [String] optional
87
+ # @param speed [Float] optional
88
+ # @param format [String] optional (default "aac"):
89
+ # - "aac"
90
+ # - "mp3"
91
+ # - "flac"
92
+ # - "opus"
93
+ # - "pcm"
94
+ # - "wav"
95
+ #
96
+ # @yield [output] optional
97
+ #
98
+ # @return [Tempfile``]
99
+ def speak(input, model: Speak::Model::TTS_1_HD, voice: Speak::Voice::ALLOY, speed: nil, format: nil, &)
100
+ Speak.process!(input, model:, voice:, speed:, format:, client: self, &)
101
+ end
81
102
  end
82
103
  end
83
104
  end
@@ -4,7 +4,7 @@ module OmniAI
4
4
  module OpenAI
5
5
  # Configuration for managing the OpenAI `api_key` / `organization` / `project` / `logger`.
6
6
  class Config < OmniAI::Config
7
- attr_accessor :organization, :project, :chat_options, :transcribe_options
7
+ attr_accessor :organization, :project, :chat_options, :transcribe_options, :speak_options
8
8
 
9
9
  def initialize
10
10
  super
@@ -14,6 +14,7 @@ module OmniAI
14
14
  @host = ENV.fetch('OPENAI_HOST', 'https://api.openai.com')
15
15
  @chat_options = {}
16
16
  @transcribe_options = {}
17
+ @speak_options = {}
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module OpenAI
5
+ # An OpenAI transcribe implementation.
6
+ class Speak < OmniAI::Speak
7
+ module Model
8
+ TTS_1 = 'tts-1'
9
+ TTS_1_HD = 'tts-1-hd'
10
+ end
11
+
12
+ module Voice
13
+ ALLOY = 'alloy' # https://platform.openai.com/docs/guides/text-to-speech/alloy
14
+ ECHO = 'echo' # https://platform.openai.com/docs/guides/text-to-speech/echo
15
+ FABLE = 'fable' # https://platform.openai.com/docs/guides/text-to-speech/fable
16
+ NOVA = 'nova' # https://platform.openai.com/docs/guides/text-to-speech/nova
17
+ ONYX = 'onyx' # https://platform.openai.com/docs/guides/text-to-speech/onyx
18
+ SHIMMER = 'shimmer' # https://platform.openai.com/docs/guides/text-to-speech/shimmer
19
+ end
20
+
21
+ protected
22
+
23
+ # @return [Hash]
24
+ def payload
25
+ OmniAI::OpenAI
26
+ .config.speak_options
27
+ .merge(super)
28
+ .merge({ response_format: @format }.compact)
29
+ end
30
+
31
+ # @return [String]
32
+ def path
33
+ "/#{OmniAI::OpenAI::Client::VERSION}/audio/speech"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -65,6 +65,7 @@ files:
65
65
  - lib/omniai/openai/chat.rb
66
66
  - lib/omniai/openai/client.rb
67
67
  - lib/omniai/openai/config.rb
68
+ - lib/omniai/openai/speak.rb
68
69
  - lib/omniai/openai/transcribe.rb
69
70
  - lib/omniai/openai/version.rb
70
71
  homepage: https://github.com/ksylvest/omniai-openai