Jump to content

Speech synthesis: Difference between revisions

(Adds Clojure solution)
Line 248:
=={{header|Scala}}==
[[Category:Scala Implementations]]
{{libheader|FreeTTS|1.2}}<lang scala>import javax.speech.Central
import javax.speech.synthesis.{ Synthesizer, SynthesizerModeDesc }
<lang scala>import java.util.Locale
import com.sun.speech.freetts._
 
import javax.speech.Central
import javax.speech.synthesis.{ Synthesizer, SynthesizerModeDesc }
 
object ScalaSpeaker extends App {
 
def speech(text: String) = {
if (!text.trim.isEmpty()) {
val VOICENAME = "kevin16"
 
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory")
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral")
 
val synth = Central.createSynthesizer(new SynthesizerModeDesc(Locale.US)null)
synth.allocate()
 
val desc = synth.getEngineModeDesc() match {case g2: SynthesizerModeDesc => g2}
 
case g2: SynthesizerModeDesc => g2
synth.getSynthesizerProperties.setVoice(desc.getVoices().find(_.toString() == VOICENAME).get)
}
synth.speakspeakPlainText(text, null)
synth.getSynthesizerProperties()
.setVoice(desc.getVoices().find(_.toString() == VOICENAME).get)
synth.speak(text, null)
 
synth.waitEngineState(Synthesizer.QUEUE_EMPTY)
Line 280 ⟶ 273:
}
 
speech( "If""Thinking itof ain't Dutch, It ain't much.")Holland
|I see broad rivers
|slowly chuntering
|through endless lowlands,
|rows of implausibly
|airy poplars
|standing like tall plumes
|against the horizon;
|and sunk in the unbounded
|vastness of space
|homesteads and boweries
|dotted across the land,
|copses, villages,
|couchant towers,
|churches and elm-trees,
|bound in one great unity.
|There the sky hangs low,
|and steadily the sun
|is smothered in a greyly
|iridescent smirr,
|and in every province
|the voice of water
|with its lapping disasters
|is feared and hearkened.""".stripMargin)
}</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.