Class: ElevenlabsClient::Admin::PronunciationDictionaries

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ PronunciationDictionaries

Returns a new instance of PronunciationDictionaries.



6
7
8
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#add_from_file(name:, file_io: nil, filename: nil, description: nil, workspace_access: nil) ⇒ Object Also known as: create_from_file

POST /v1/pronunciation-dictionaries/add-from-file (multipart) Creates a new pronunciation dictionary from a lexicon .PLS file Required: name Optional: file (IO + filename), description, workspace_access

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 14

def add_from_file(name:, file_io: nil, filename: nil, description: nil, workspace_access: nil)
  raise ArgumentError, "name is required" if name.nil? || name.to_s.strip.empty?

  endpoint = "/v1/pronunciation-dictionaries/add-from-file"
  payload = { name: name }
  payload[:description] = description if description
  payload[:workspace_access] = workspace_access if workspace_access

  if file_io && filename
    payload[:file] = @client.file_part(file_io, filename)
  end

  @client.post_multipart(endpoint, payload)
end

#add_from_rules(name:, rules:, description: nil, workspace_access: nil) ⇒ Object Also known as: create_from_rules

POST /v1/pronunciation-dictionaries/add-from-rules (json) Creates a new pronunciation dictionary from provided rules Required: name, rules (Array) Optional: description, workspace_access

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 35

def add_from_rules(name:, rules:, description: nil, workspace_access: nil)
  raise ArgumentError, "name is required" if name.nil? || name.to_s.strip.empty?
  raise ArgumentError, "rules must be a non-empty Array" unless rules.is_a?(Array) && !rules.empty?

  endpoint = "/v1/pronunciation-dictionaries/add-from-rules"
  body = { name: name, rules: rules }
  body[:description] = description if description
  body[:workspace_access] = workspace_access if workspace_access

  @client.post(endpoint, body)
end

#download_pronunciation_dictionary_version(dictionary_id:, version_id:) ⇒ Object Also known as: download_version

GET /v1/pronunciation-dictionaries/:dictionary_id/:version_id/download Returns raw PLS file contents

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 71

def download_pronunciation_dictionary_version(dictionary_id:, version_id:)
  raise ArgumentError, "dictionary_id is required" if dictionary_id.nil? || dictionary_id.to_s.strip.empty?
  raise ArgumentError, "version_id is required" if version_id.nil? || version_id.to_s.strip.empty?

  endpoint = "/v1/pronunciation-dictionaries/#{dictionary_id}/#{version_id}/download"
  @client.get_binary(endpoint)
end

#get_pronunciation_dictionary(pronunciation_dictionary_id) ⇒ Object Also known as: get

GET /v1/pronunciation-dictionaries/:pronunciation_dictionary_id

Raises:

  • (ArgumentError)


50
51
52
53
54
55
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 50

def get_pronunciation_dictionary(pronunciation_dictionary_id)
  raise ArgumentError, "pronunciation_dictionary_id is required" if pronunciation_dictionary_id.nil? || pronunciation_dictionary_id.to_s.strip.empty?

  endpoint = "/v1/pronunciation-dictionaries/#{pronunciation_dictionary_id}"
  @client.get(endpoint)
end

#list_pronunciation_dictionaries(cursor: nil, page_size: nil, sort: nil, sort_direction: nil) ⇒ Object Also known as: list

GET /v1/pronunciation-dictionaries Optional query: cursor, page_size, sort, sort_direction



83
84
85
86
87
88
89
90
91
92
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 83

def list_pronunciation_dictionaries(cursor: nil, page_size: nil, sort: nil, sort_direction: nil)
  params = {
    cursor: cursor,
    page_size: page_size,
    sort: sort,
    sort_direction: sort_direction
  }.compact

  @client.get("/v1/pronunciation-dictionaries", params)
end

#update_pronunciation_dictionary(pronunciation_dictionary_id, **attributes) ⇒ Object Also known as: update

PATCH /v1/pronunciation-dictionaries/:pronunciation_dictionary_id Accepts partial attributes like archived, name, description, workspace_access

Raises:

  • (ArgumentError)


61
62
63
64
65
# File 'lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb', line 61

def update_pronunciation_dictionary(pronunciation_dictionary_id, **attributes)
  raise ArgumentError, "pronunciation_dictionary_id is required" if pronunciation_dictionary_id.nil? || pronunciation_dictionary_id.to_s.strip.empty?
  endpoint = "/v1/pronunciation-dictionaries/#{pronunciation_dictionary_id}"
  @client.patch(endpoint, attributes)
end