<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import json
import platform
import shutil
import subprocess
import sys
import tempfile
import urllib2

if __name__ == "__main__":
  APIKEY = "1953c74c5b60c0e3bdabaeb822e4e14c"

  parser = argparse.ArgumentParser(prog='pySay', usage='%(prog)s [options]',
      description='Pronounce a specified word or phrase in its native language.')

  parser.add_argument('word', help="A word or phrase to pronounce.")
  parser.add_argument('-l','--lang', help="A two character language code, e.g. 'en' or 'ru'."
      "(default: automatically inferred from word or phrase entered.)")
  parser.add_argument('-s','--sex', help="The sex of the speaker pronouncing the specified word.")
  parser.add_argument('-a','--action', default="standard-pronunciation",
      help="Set to 'word-pronunciations' for varying audio examples, or 'standard-pronounciation' for top rated result." +
      "(default: Top rated pronunciation of desired word)")

  args = parser.parse_args()

  url =  "http://apifree.forvo.com/limit/1/format/json/key/" + APIKEY
  url += "/action/" + args.action
  url += "/word/" + args.word #No need to validate as 'too few arguments' error is throw if no argument passed.

  if args.lang:
    url += "/language/" + args.lang

  if args.sex:
    url += "/sex/" + args.sex

  data = json.load(urllib2.urlopen(url))

  if not data['items']:
    print "No results were found for the word (" + args.word + ") that you specified."
    sys.exit()

  audioRequest = urllib2.urlopen(data['items'][0]['pathmp3'])

  tf = tempfile.NamedTemporaryFile()

  with open(tf.name, 'wb') as f:
    shutil.copyfileobj(audioRequest,f)

  if platform.system() == 'Darwin':
    subprocess.call(["afplay",tf.name])
  else:
    subprocess.call(["mplayer","-really-quiet",tf.name])<commit_msg>Sex option now works correctly.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import json
import platform
import shutil
import subprocess
import sys
import tempfile
import urllib2

if __name__ == "__main__":
  APIKEY = "1953c74c5b60c0e3bdabaeb822e4e14c"

  parser = argparse.ArgumentParser(prog='pySay', usage='%(prog)s [options]',
      description='Pronounce a specified word or phrase in its native language.')

  parser.add_argument('word', help="A word or phrase to pronounce.")
  parser.add_argument('-l','--lang', help="A two character language code, e.g. 'en' or 'ru'."
      "(default: automatically inferred from word or phrase entered.)")
  parser.add_argument('-s','--sex', help="The sex of the speaker pronouncing the specified word.")
  parser.add_argument('-a','--action', default="standard-pronunciation",
      help="Set to 'word-pronunciations' for varying audio examples, or 'standard-pronounciation' for top rated result." +
      "(default: Top rated pronunciation of desired word)")

  args = parser.parse_args()

  url =  "http://apifree.forvo.com/limit/1/format/json/key/" + APIKEY
  url += "/word/" + args.word #No need to validate as 'too few arguments' error is throw if no argument passed.

  if args.lang:
    url += "/language/" + args.lang

  if args.sex:
    url += "/sex/" + args.sex
    url += "/action/" + "word-pronunciations/"
  else:
    url += "/action/" + args.action

  data = json.load(urllib2.urlopen(url))

  if not data['items']:
    print "No results were found for the word (" + args.word + ") that you specified."
    sys.exit()

  audioRequest = urllib2.urlopen(data['items'][0]['pathmp3'])

  tf = tempfile.NamedTemporaryFile()

  with open(tf.name, 'wb') as f:
    shutil.copyfileobj(audioRequest,f)

  if platform.system() == 'Darwin':
    subprocess.call(["afplay",tf.name])
  else:
    subprocess.call(["mplayer","-really-quiet",tf.name])
{'fraction_non_alphanumeric': 0.15202971610506766, 'fraction_numerical': 0.012735473600424516, 'mean_word_length': 3.9216710182767622, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4677830', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1208, 'n_words': 339}