DocomoTextToSpeech v0.3.0 DocomoTextToSpeech View Source

Elixir client for NTT Docomo TextToSpeech API.

Installation

The package can be installed by adding docomo_text_to_speech to your list of dependencies in mix.exs:

def deps do
  [
    {:docomo_text_to_speech, "~> 0.3.0"}
  ]
end

Configuration

Get your API key from docomo Developer support site.

Set the API key to your system environment variable.

export DOCOMO_TEXT_TO_SPEECH_API_KEY="secret"

In your config.exs, set the api_key from the system environment variable.

config :docomo_text_to_speech,
  api_key: "secret"

Usage

iex> DocomoTextToSpeech.run!("エリクサー") |> (&File.write("output.wav", &1)).()

License

DocomoTextToSpeech is licensed under the MIT License.

Link to this section Summary

Types

Text to speech conversion option

Functions

Converts text to speech.

Returns the audio file directly or raise exception if any errors.

Link to this section Types

Link to this type

conversion_option()

View Source
conversion_option() ::
  {:command, String.t()}
  | {:speaker_id, pos_integer()}
  | {:style_id, pos_integer()}
  | {:speech_rate, float()}
  | {:power_rate, float()}
  | {:voice_type, float()}
  | {:audio_file_format, pos_integer()}

Text to speech conversion option

Link to this type

option()

View Source
option() ::
  {:method, Tesla.Env.method()}
  | {:url, Tesla.Env.url()}
  | {:query, Tesla.Env.query()}
  | {:headers, Tesla.Env.headers()}
  | {:body, Tesla.Env.body()}
  | {:opts, Tesla.Env.opts()}

Link to this section Functions

Link to this function

run(text, opts \\ [])

View Source
run(String.t(), [conversion_option()]) :: {:ok | :error, any()}

Converts text to speech.

Examples

With valid API key.

iex> DocomoTextToSpeech.run "エリクサー"
{:ok,
 <<82, 73, 70, 70, 28, 199, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32, 18, 0, 0,
 0, 1, 0, 1, 0, 34, 86, 0, 0, 68, 172, 0, 0, 2, 0, 16, 0, 0, 0, 100, 97, 116,
 97, 246, 198, 0, 0, 0, 0, ...>>}

Without valid API key.

iex> DocomoTextToSpeech.run "エリクサー"
{:error, "(401) POLSLA009: Unable to perform ApiKey based Authentication"}

Without APIKEY URL param.

iex> DocomoTextToSpeech.run "エリクサー"
{:error, "(401) POLSLA009: APIKEY is null or empty in the request"}

iex(5)> DocomoTextToSpeech.run! "エリクサー"
** (RuntimeError) (401) POLSLA009: Unable to perform ApiKey based Authentication
    (docomo_text_to_speech) lib/docomo_text_to_speech.ex:97: DocomoTextToSpeech.run!/2
Link to this function

run!(text, opts \\ [])

View Source
run!(String.t(), [conversion_option()]) :: {:ok | :error, any()} | no_return()

Returns the audio file directly or raise exception if any errors.

Examples

Successfull convertion.

iex> DocomoTextToSpeech.run! "エリクサー"
<<82, 73, 70, 70, 28, 199, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32, 18, 0, 0,
  0, 1, 0, 1, 0, 34, 86, 0, 0, 68, 172, 0, 0, 2, 0, 16, 0, 0, 0, 100, 97, 116,
  97, 246, 198, 0, 0, 0, 0, ...>>

Failed conversion.

iex(4)> DocomoTextToSpeech.run! "エリクサー"
** (RuntimeError) (401) POLSLA009: APIKEY is null or empty in the request
    (docomo_text_to_speech) lib/docomo_text_to_speech.ex:96: DocomoTextToSpeech.run!/2