Speech synthesis: Difference between revisions

From Rosetta Code
Content added Content deleted
(added omit from ML/I)
Line 81: Line 81:


<lang zx basic>10 LET s$="(th)is is an exampul of sp(ee)(ch) sin(th)esis":PAUSE 1</lang>
<lang zx basic>10 LET s$="(th)is is an exampul of sp(ee)(ch) sin(th)esis":PAUSE 1</lang>


{{omit from|ML/I}}

Revision as of 19:12, 14 August 2011

Task
Speech synthesis
You are encouraged to solve this task according to the task description, using any language you may know.

Render the text “This is an example of speech synthesis.” as speech.

C

Following shining examples of execing external programs around here:<lang c>#include <unistd.h>

  1. include <sys/wait.h>

int talk(char *s) { if (fork()) return wait(0); execlp("espeak", s, (void*)0); return -1; }

int main() { talk("Blah blah"); return 0; }</lang>

C#

You need to 'Add Reference' to the COM "Microsoft Speech Object Library" in your Preferences. <lang csharp>using SpeechLib;

namespace Speaking_Computer {

 public class Program
 {
   private static void Main()
   {
     var voice = new SpVoice();
     voice.Speak("This is an example of speech synthesis.");
   }
 }

}</lang>

Mathematica

<lang Mathematica>Speak["This is an example of speech synthesis."]</lang>


PicoLisp

<lang PicoLisp>(call 'espeak "This is an example of speech synthesis.")</lang>

Tcl

This just passes the string into the Festival system: <lang tcl>exec festival --tts << "This is an example of speech synthesis."</lang> Alternatively, on MacOS X, you'd use the system say program: <lang tcl>exec say << "This is an example of speech synthesis."</lang> On Windows, there is a service available by COM for speech synthesis:

Library: tcom

<lang tcl>package require tcom

set msg "This is an example of speech synthesis." set voice [::tcom::ref createobject Sapi.SpVoice] $voice Speak $msg 0</lang> Putting these together into a helper procedure, we get: <lang tcl>proc speak {msg} {

   global tcl_platform
   if {$tcl_platform(platform) eq "windows"} {
       package require tcom
       set voice [::tcom::ref createobject Sapi.SpVoice]
       $voice Speak $msg 0
   } elseif {$tcl_platform(os) eq "Darwin"} {
       exec say << $msg
   } else {
       exec festival --tts << $msg
   }

} speak "This is an example of speech synthesis."</lang>

UNIX Shell

Here we use the open source espeak tool:

Works with: Bourne Shell
Works with: bash

<lang bash>#!/bin/sh espeak "This is an example of speech synthesis."</lang>

ZX Spectrum Basic

This example makes use of the Currah Speech Synthesizer peripheral device.

<lang zx basic>10 LET s$="(th)is is an exampul of sp(ee)(ch) sin(th)esis":PAUSE 1</lang>