<commit_before>package info.spielproject.spiel

import actors.Actor._
import collection.JavaConversions._

import android.content.Context
import android.os.Build.VERSION
import android.os.Environment
import android.speech.tts.TextToSpeech
import android.util.Log

/**
 * Singleton facade around TTS functionality.
*/

object TTS extends TextToSpeech.OnInitListener with TextToSpeech.OnUtteranceCompletedListener {

  private var tts:TextToSpeech = null

  private var context:Context = null

  /**
   * Initialize TTS based on specified <code>Context</code>.
  */

  def apply(c:Context) {
    context = c
    init()
  }

  /**
   * Initialize or re-initialize TTS.
  */

  def init() = {
    tts = new TextToSpeech(context, this)
  }

  private var welcomed = false

  def onInit(status:Int) {
    tts.setLanguage(java.util.Locale.getDefault)
    if(Environment.getExternalStorageState == Environment.MEDIA_MOUNTED)
      engine = Preferences.speechEngine
    else
      engine = "com.svox.pico"
    tts.setOnUtteranceCompletedListener(this)
    this.rate = Preferences.rateScale
    this.pitch = Preferences.pitchScale
    tts.addEarcon("tick", "info.spielproject.spiel", R.raw.tick)
    if(!welcomed) {
      speak(context.getString(R.string.welcomeMsg), true)
      welcomed = true
    }
  }

  /**
   * @return default engine, or empty string if unknown
  */

  def defaultEngine = {
    Log.d("spiel", "Delegating defaultEngine() for API level "+VERSION.SDK_INT)
    if(VERSION.SDK_INT >= 8) defaultEngineV8 else ""
  }

  private def defaultEngineV8 = {
    Log.d("spiel", "defaultEngineV8")<commit_msg>TTS.areDefaultsEnforced is a V8 or later thing, oopse.<commit_after>package info.spielproject.spiel

import actors.Actor._
import collection.JavaConversions._

import android.content.Context
import android.os.Build.VERSION
import android.os.Environment
import android.speech.tts.TextToSpeech
import android.util.Log

/**
 * Singleton facade around TTS functionality.
*/

object TTS extends TextToSpeech.OnInitListener with TextToSpeech.OnUtteranceCompletedListener {

  private var tts:TextToSpeech = null

  private var context:Context = null

  /**
   * Initialize TTS based on specified <code>Context</code>.
  */

  def apply(c:Context) {
    context = c
    init()
  }

  /**
   * Initialize or re-initialize TTS.
  */

  def init() = {
    tts = new TextToSpeech(context, this)
  }

  private var welcomed = false

  def onInit(status:Int) {
    tts.setLanguage(java.util.Locale.getDefault)
    if(Environment.getExternalStorageState == Environment.MEDIA_MOUNTED)
      engine = Preferences.speechEngine
    else
      engine = "com.svox.pico"
    tts.setOnUtteranceCompletedListener(this)
    this.rate = Preferences.rateScale
    this.pitch = Preferences.pitchScale
    tts.addEarcon("tick", "info.spielproject.spiel", R.raw.tick)
    if(!welcomed) {
      speak(context.getString(R.string.welcomeMsg), true)
      welcomed = true
    }
  }

  def defaultsEnforced_? = {
    if(VERSION.SDK_INT >= 8) defaultsEnforcedV8_? else false
  }

  private def defaultsEnforcedV8_? = tts.areDefaultsEnforced()

  /**
   * @return default engine, or empty string if unknown
  */

  def defaultEngine = {
    Log.d("spiel", "Delegating defaultEngine() for API level "+VERSION.SDK_INT)
    if(VERSION.SDK_INT >= 8) defaultEngineV8 else ""
  }

  private def defaultEngineV8 = {
    Log.d("spiel", "defaultEngineV8")
{'fraction_non_alphanumeric': 0.1064327485380117, 'fraction_numerical': 0.0035087719298245615, 'mean_word_length': 3.5981182795698925, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6123613', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1093, 'n_words': 235}