screenkit 0.0.7 → 0.0.8
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/DOCUMENTATION.md +27 -11
- data/lib/screenkit/http.rb +58 -0
- data/lib/screenkit/tts/base.rb +16 -7
- data/lib/screenkit/tts/eleven_labs.rb +8 -23
- data/lib/screenkit/version.rb +1 -1
- data/lib/screenkit.rb +2 -0
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9432b0beeacae6f145c48e9935c18d92c62c08c69ea7177a3d282db689b0d9d5
|
|
4
|
+
data.tar.gz: 9cbf970a8998f0cb3bd5778489faa0ecc521b800862c1d8c8112cb11e0232bcd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b952dc0d719ccdf1496b2ee0cb430e9ba8271e5e9373f1859d8132ed68febf86daa9ff063cbc05a75a314de32d8a279eb4336021344caf70e9cc297e8eaac37
|
|
7
|
+
data.tar.gz: 4660532603407564ab3315a0d21d6af592d5fad3179cbd7bafade4438e97708a95ba2d9eab34fd61507aee02b58c90bed5d487f7affa4951351a1d3442c37d46
|
data/CHANGELOG.md
CHANGED
data/DOCUMENTATION.md
CHANGED
|
@@ -719,7 +719,9 @@ tts:
|
|
|
719
719
|
|
|
720
720
|
### ElevenLabs Engine
|
|
721
721
|
|
|
722
|
-
|
|
722
|
+
The ElevenLabs TTS engine requires an API key. Set it via the `--tts-api-key`
|
|
723
|
+
option when exporting an episode. The API key must be prefixed with
|
|
724
|
+
`eleven_labs:`, e.g. `eleven_labs:sk_c195c0131de...`.
|
|
723
725
|
|
|
724
726
|
```yaml
|
|
725
727
|
tts:
|
|
@@ -764,21 +766,26 @@ module. Custom engines must implement the `generate` method:
|
|
|
764
766
|
module ScreenKit
|
|
765
767
|
module TTS
|
|
766
768
|
class CustomEngine < Base
|
|
767
|
-
extend Shell
|
|
768
|
-
|
|
769
769
|
# Optional: Define schema path for validation
|
|
770
770
|
def self.schema_path
|
|
771
|
-
|
|
771
|
+
File.join(__dir__, "yourschema.json")
|
|
772
772
|
end
|
|
773
773
|
|
|
774
774
|
# This method is required.
|
|
775
|
+
# The keyword arguments will be all the configuration options, plus
|
|
776
|
+
# api_key and segments. If you don't care about those, remember to use
|
|
777
|
+
# the `**` operator to ignore them.
|
|
775
778
|
def self.available?(**)
|
|
776
|
-
|
|
779
|
+
# If you're running a local command:
|
|
780
|
+
# command_exist?("some-command")
|
|
781
|
+
|
|
782
|
+
# If you're using an API key:
|
|
783
|
+
# api_key.to_s.start_with?("#{engine_name}:")
|
|
777
784
|
end
|
|
778
785
|
|
|
779
786
|
# This method is required.
|
|
780
787
|
def generate(text:, output_path:, log_path: nil)
|
|
781
|
-
# Optional: validate options against JSON schema.
|
|
788
|
+
# Optional, but recommended: validate options against JSON schema.
|
|
782
789
|
self.class.validate!(options)
|
|
783
790
|
|
|
784
791
|
# If you need access to previous/next text, you can access the method
|
|
@@ -790,11 +797,19 @@ module ScreenKit
|
|
|
790
797
|
# Write output to output_path
|
|
791
798
|
# Optionally log to log_path
|
|
792
799
|
|
|
793
|
-
# Example
|
|
800
|
+
# Example calling a command (provided by ScreenKit::Shell)
|
|
794
801
|
# self.class.run_command "some-command",
|
|
795
802
|
# "-o", output_path.sub_ext(".wav"),
|
|
796
803
|
# text,
|
|
797
804
|
# log_path:
|
|
805
|
+
|
|
806
|
+
# Example using an API (provided by ScreenKit::HTTP)
|
|
807
|
+
# response = json_post(
|
|
808
|
+
# url: "https://api.example.com/tts",
|
|
809
|
+
# headers: {authorization: "Bearer #{api_key}"},
|
|
810
|
+
# api_key:,
|
|
811
|
+
# log_path:
|
|
812
|
+
# )
|
|
798
813
|
end
|
|
799
814
|
end
|
|
800
815
|
end
|
|
@@ -821,6 +836,7 @@ The engine name is camelized (e.g., `custom_engine` → `CustomEngine`,
|
|
|
821
836
|
|
|
822
837
|
- [Search Github](https://github.com/topics/screenkit-tts)
|
|
823
838
|
- [Google Text to Speech](https://github.com/fnando/screenkit-tts-google)
|
|
839
|
+
- [Minimax Text to Speech](https://github.com/fnando/screenkit-tts-minimax)
|
|
824
840
|
|
|
825
841
|
> [!TIP]
|
|
826
842
|
>
|
|
@@ -1121,26 +1137,26 @@ be processed).
|
|
|
1121
1137
|
|
|
1122
1138
|
### Common Issues
|
|
1123
1139
|
|
|
1124
|
-
|
|
1140
|
+
#### "Gem not found" error
|
|
1125
1141
|
|
|
1126
1142
|
```bash
|
|
1127
1143
|
bundle install
|
|
1128
1144
|
bundle exec screenkit ...
|
|
1129
1145
|
```
|
|
1130
1146
|
|
|
1131
|
-
|
|
1147
|
+
#### Schema validation failed
|
|
1132
1148
|
|
|
1133
1149
|
- Check YAML syntax
|
|
1134
1150
|
- Verify required fields are present
|
|
1135
1151
|
- Use schema hints with `yaml-language-server`
|
|
1136
1152
|
|
|
1137
|
-
|
|
1153
|
+
#### Missing resources
|
|
1138
1154
|
|
|
1139
1155
|
- Check `resources_dir` configuration
|
|
1140
1156
|
- Verify file paths are relative to resource directories
|
|
1141
1157
|
- Use absolute paths for system resources
|
|
1142
1158
|
|
|
1143
|
-
|
|
1159
|
+
#### TTS not working
|
|
1144
1160
|
|
|
1145
1161
|
- For ElevenLabs: Set `--tts-api-key`
|
|
1146
1162
|
- For macOS `say`: Verify voice name with `say -v ?`
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ScreenKit
|
|
4
|
+
module HTTP
|
|
5
|
+
# Sends a POST request.
|
|
6
|
+
# @param url [String] The request URL.
|
|
7
|
+
# @param params [Hash] The request parameters.
|
|
8
|
+
# @param headers [Hash] The request headers.
|
|
9
|
+
# @param api_key [String] The API key to redact from logs.
|
|
10
|
+
# @param log_path [String, nil] The path to log the request details.
|
|
11
|
+
# @return [Aitch::Response] The response.
|
|
12
|
+
def post(url:, params:, headers:, api_key:, log_path: nil)
|
|
13
|
+
if log_path
|
|
14
|
+
File.open(log_path, "w") do |f|
|
|
15
|
+
f << JSON.pretty_generate(url:, params:, headers:)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
client = Aitch::Namespace.new
|
|
20
|
+
client.configure do |config|
|
|
21
|
+
config.logger = Logger.new(log_path) if log_path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
client.post(
|
|
25
|
+
url:,
|
|
26
|
+
params:,
|
|
27
|
+
options: {expect: 200},
|
|
28
|
+
headers: headers.merge(user_agent: "ScreenKit/#{ScreenKit::VERSION}")
|
|
29
|
+
)
|
|
30
|
+
ensure
|
|
31
|
+
redact_file(log_path, api_key)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Sends a JSON POST request.
|
|
35
|
+
# @param url [String] The request URL.
|
|
36
|
+
# @param params [Hash] The request parameters.
|
|
37
|
+
# @param headers [Hash] The request headers.
|
|
38
|
+
# @param api_key [String] The API key to redact from logs.
|
|
39
|
+
# @param log_path [String, nil] The path to log the request details.
|
|
40
|
+
# @return [Aitch::Response] The response.
|
|
41
|
+
def json_post(headers:, **)
|
|
42
|
+
headers = headers.merge(content_type: "application/json")
|
|
43
|
+
post(headers:, **)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Redacts sensitive text from a file.
|
|
47
|
+
# @param path [String] The file path.
|
|
48
|
+
# @param text [String] The text to redact.
|
|
49
|
+
# @return [void]
|
|
50
|
+
def redact_file(path, text)
|
|
51
|
+
return unless path
|
|
52
|
+
return unless File.file?(path)
|
|
53
|
+
|
|
54
|
+
content = File.read(path).gsub(text, "[REDACTED]")
|
|
55
|
+
File.write(path, content)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/screenkit/tts/base.rb
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json-schema"
|
|
4
|
+
require "aitch"
|
|
5
|
+
require "logger"
|
|
6
|
+
|
|
3
7
|
module ScreenKit
|
|
4
8
|
module TTS
|
|
5
9
|
class Base
|
|
6
|
-
require_relative "../core_ext"
|
|
7
10
|
require_relative "../schema_validator"
|
|
11
|
+
require_relative "../shell"
|
|
12
|
+
require_relative "../http"
|
|
13
|
+
require_relative "../core_ext"
|
|
14
|
+
require_relative "../version"
|
|
8
15
|
|
|
9
16
|
extend SchemaValidator
|
|
17
|
+
extend Shell
|
|
18
|
+
include HTTP
|
|
10
19
|
|
|
11
20
|
using CoreExt
|
|
12
21
|
|
|
@@ -33,18 +42,18 @@ module ScreenKit
|
|
|
33
42
|
name.split("::").last.underscore
|
|
34
43
|
end
|
|
35
44
|
|
|
45
|
+
def self.api_key_prefix
|
|
46
|
+
"#{engine_name}:"
|
|
47
|
+
end
|
|
48
|
+
|
|
36
49
|
def initialize(id: nil, segments: nil, api_key: nil, **options)
|
|
37
50
|
@segments = Array(segments)
|
|
38
51
|
@options = options
|
|
39
52
|
@id = id
|
|
40
|
-
@api_key = api_key
|
|
41
|
-
end
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
return unless File.file?(path)
|
|
54
|
+
return unless api_key
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
File.write(path, content)
|
|
56
|
+
@api_key = api_key.delete_prefix("#{self.class.engine_name}:")
|
|
48
57
|
end
|
|
49
58
|
end
|
|
50
59
|
end
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
module ScreenKit
|
|
4
4
|
module TTS
|
|
5
5
|
class ElevenLabs < Base
|
|
6
|
+
include HTTP
|
|
7
|
+
|
|
6
8
|
def self.schema_path
|
|
7
9
|
ScreenKit.root_dir
|
|
8
10
|
.join("screenkit/schemas/tts/elevenlabs.json")
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def self.available?(api_key: nil, **)
|
|
12
|
-
api_key.to_s.
|
|
14
|
+
api_key.to_s.start_with?(api_key_prefix)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def all_texts
|
|
@@ -19,18 +21,6 @@ module ScreenKit
|
|
|
19
21
|
def generate(output_path:, text:, log_path: nil)
|
|
20
22
|
voice_id = options[:voice_id]
|
|
21
23
|
|
|
22
|
-
if log_path
|
|
23
|
-
File.open(log_path, "w") do |f|
|
|
24
|
-
f << JSON.pretty_generate(options.merge(text:))
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
require "aitch"
|
|
29
|
-
|
|
30
|
-
Aitch.configure do |config|
|
|
31
|
-
config.logger = Logger.new(log_path) if log_path
|
|
32
|
-
end
|
|
33
|
-
|
|
34
24
|
current_index = all_texts.index { it == text }
|
|
35
25
|
|
|
36
26
|
if current_index
|
|
@@ -41,20 +31,15 @@ module ScreenKit
|
|
|
41
31
|
params = options.merge(text:, previous_text:, next_text:)
|
|
42
32
|
.except(:voice_id)
|
|
43
33
|
|
|
44
|
-
response =
|
|
34
|
+
response = json_post(
|
|
45
35
|
url: "https://api.elevenlabs.io/v1/text-to-speech/#{voice_id}",
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"user-agent": "ScreenKit/#{ScreenKit::VERSION}",
|
|
51
|
-
"xi-api-key": api_key
|
|
52
|
-
}
|
|
36
|
+
params:,
|
|
37
|
+
headers: {"xi-api-key": api_key},
|
|
38
|
+
api_key:,
|
|
39
|
+
log_path:
|
|
53
40
|
)
|
|
54
41
|
|
|
55
42
|
File.binwrite(output_path, response.body)
|
|
56
|
-
ensure
|
|
57
|
-
redact_file(log_path, api_key)
|
|
58
43
|
end
|
|
59
44
|
end
|
|
60
45
|
end
|
data/lib/screenkit/version.rb
CHANGED
data/lib/screenkit.rb
CHANGED
|
@@ -10,6 +10,7 @@ require "tty-spinner"
|
|
|
10
10
|
require "etc"
|
|
11
11
|
require "securerandom"
|
|
12
12
|
require "demo_tape/duration"
|
|
13
|
+
require "aitch"
|
|
13
14
|
|
|
14
15
|
module ScreenKit
|
|
15
16
|
require_relative "screenkit/version"
|
|
@@ -23,6 +24,7 @@ module ScreenKit
|
|
|
23
24
|
require_relative "screenkit/watermark"
|
|
24
25
|
require_relative "screenkit/spinner"
|
|
25
26
|
require_relative "screenkit/shell"
|
|
27
|
+
require_relative "screenkit/http"
|
|
26
28
|
require_relative "screenkit/schema_validator"
|
|
27
29
|
require_relative "screenkit/generators/project"
|
|
28
30
|
require_relative "screenkit/generators/episode"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: screenkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nando Vieira
|
|
@@ -328,6 +328,7 @@ files:
|
|
|
328
328
|
- lib/screenkit/generators/project/resources/sounds/pop.mp3
|
|
329
329
|
- lib/screenkit/generators/project/resources/sounds/whoosh.mp3
|
|
330
330
|
- lib/screenkit/generators/project/screenkit.yml
|
|
331
|
+
- lib/screenkit/http.rb
|
|
331
332
|
- lib/screenkit/logfile.rb
|
|
332
333
|
- lib/screenkit/parallel_processor.rb
|
|
333
334
|
- lib/screenkit/path_lookup.rb
|
|
@@ -387,10 +388,10 @@ metadata:
|
|
|
387
388
|
rubygems_mfa_required: 'true'
|
|
388
389
|
homepage_uri: https://github.com/fnando/screenkit
|
|
389
390
|
bug_tracker_uri: https://github.com/fnando/screenkit/issues
|
|
390
|
-
source_code_uri: https://github.com/fnando/screenkit/tree/v0.0.
|
|
391
|
-
changelog_uri: https://github.com/fnando/screenkit/tree/v0.0.
|
|
392
|
-
documentation_uri: https://github.com/fnando/screenkit/tree/v0.0.
|
|
393
|
-
license_uri: https://github.com/fnando/screenkit/tree/v0.0.
|
|
391
|
+
source_code_uri: https://github.com/fnando/screenkit/tree/v0.0.8
|
|
392
|
+
changelog_uri: https://github.com/fnando/screenkit/tree/v0.0.8/CHANGELOG.md
|
|
393
|
+
documentation_uri: https://github.com/fnando/screenkit/tree/v0.0.8/README.md
|
|
394
|
+
license_uri: https://github.com/fnando/screenkit/tree/v0.0.8/LICENSE.md
|
|
394
395
|
rdoc_options: []
|
|
395
396
|
require_paths:
|
|
396
397
|
- lib
|