Firef0x / forvocl

Play, list, and save Forvo pronunciations from the command-line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forvocl is a command-line tool for accessing the API provided by Forvo. Using forvocl you can list, play back, get information on, and save audio pronunciations contributed by users of the site.

Requirements

  • mplayer
  • a Forvo API key

Installation

To install you can either download the project source and run the script directly, or use a package manager to install the appropriate files for your distro.

Installation from distro packages

User packaged

Usage

Using the forvocl.rb script you can look up and play back audio pronunciations from Forvo. This requires registering for a Forvo API key, which is free for non-commercial educational use.

Once you have a key, you just need to copy it into your forvocl config file in your user home directory (i.e. ~/.config/forvocl/config.yml) under the section "forvo key". Uncomment the line # :forvo_key: "" and add your key between the quotation marks "". Now you can look up pronunciations by running forvocl.rb.

Location of configuration file

Forvocl will attempt to read a configuration file located at ~/.config/forvocl/config.yml. If it does not find it there (or if the directory doesn't exist, it will try looking in a few other places before giving up:

  1. If you use the gdcl dictionary lookup tool and have a config.yml file with a forvo key in ~/.config/gdcl, there is no need to create a duplicate configuration file in the forvocl directory -- forvocl will read your key from the gdcl configuration.
  2. If you prefer (or if installed by your package manager) you can use the xdg config folder instead, located at /etc/xdg/forvocl
  3. As a last resort, forvocl will check for config.yml in the same folder as the forvocl.rb executable. This could be useful if you have downloaded the source and just want to try it out with minimal set up.

If the configuration file cannot be found in any of these locations, forvocl will exit with a message explaining the situation.

Searching and playback

Forvocl has both interactive and non-interactive lookup modes. If run without any command-line arguments, it will prompt for a language code and a word to pronounce. You can find a full list of the supported codes here.

You can skip the prompts by supplying the language code and word to be pronounced as arguments when running forvocl.rb, in the form ruby forvocl.rb [lang_code] [word_to_be_pronounced]. For example, if you wanted to find the pronounciation of the word "сегодня" in Russian, you would enter:

ruby forvocl.rb ru сегодня

The last argument should probably be in quotes to avoid problems -- this also allows for pronunciation of phrases and other terms with spaces:

ruby forvocl.rb sv "Johannes Robert Rydberg"

The script will let you know how many pronunciations were found and print out a numbered list (example below):

  • command: ruby forvocl.rb zh 发音

  • output:

4 pronunciations found for "发音" in zh:

  1. by Gliese (f from China)           0 [+1 -1]
  2. by witenglish (m from China)       0 [+0 0]
  3. by cloudrainner (m from China)     0 [+0 0]
  4. by JuliaWu (f from China)          0 [+0 0]


Select a number to hear the corresponding pronunciation, or press "a" to hear all available pronunciations.

To hear any of the listed pronunciations just enter the corresponding number and it will start playing automatically. If you press "a", all of the pronunciations will play in order. The numbers to the far right are the user rating that each pronunciation has received, in the format rating [+upvotes -downvotes].

Options

The Forvo script has a number of options that can be supplied at the command-line:

  • -m, --mp3 (Use mp3 format instead of ogg)
  • -l, --list (List all pronunciations)
  • -u, --urls (Print a list of audio urls)
  • -a, --play-all (Play back all pronunciations without interaction)
  • -s, --save (Save all audio files to disk)

Many of these options can be combined, for example:

ruby forvocl.rb -lum en photogrammetry (Lookup the word "photogrammetry" and produce a list of pronunciations and urls in mp3 format)

If you want to skip all interaction entirely and just play each audio result automatically, use the -a option and supply the language code and lookup terms on the command-line, e.g.:

ruby forvocl.rb -a fr prononciation

Audio format

By default, forvocl plays back and saves audio files in ogg format. If you want to switch to using mp3 format, just use the -m option.

Saving audio files to disk

Once you have finished listening to the audio, forvocl will prompt you to enter a number from the list of available pronunciations to save the file to disk. If you don't want to save any of the audio, just press any other key to quit. To save all of the available audio files, use the -s option.

Issues

If you get the following error when playing back audio: mplayer: could not connect to socket, it just means that you need to disable LIRC support in mplayer. You can do this quite easily by editing or creating the file ~/.mplayer/config and adding the line:

        nolirc=yes

Credits

This script was originally part of the gdcl command-line dictionary project.

Table of contents generated by tocdown.

License

MIT license -- see LICENSE file for details.

The audio pronunciations on forvo are licensed cc-by-nc-sa.

About

Play, list, and save Forvo pronunciations from the command-line

License:MIT License


Languages

Language:Ruby 100.0%