ESpeak Channel Report

From AwasuWiki
Revision as of 07:55, 7 October 2010 by Kevotheclone (talk | contribs) (First Draft, Pythoin script not complete)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Draft content, not ready for publication! Problems with the Python code.

Awasu speaks to me and it can speak to you too!

Using the free and open source eSpeak software an Awasu Channel Report can be converted into a .WAV file that you can play back on your home PC or on an MP3 player. While eSpeak can perform its text-to-speech (TTS) processing on a plain text file, you can have more control and achieve better results when using a Speech Synthesis Markup Language (SSML) file, which Awasu can easily produce.

In this SSML Channel Report we'll alternate between male and female voices. The male voice with announce the "type" of data that will be spoken by the female voice. Example: The male voice will speak "Report Name" and the female voice will speak the name of the Channel Report; the male voice will speak "Feed Item Content" and the female voice will speak the actuall feed item content.

<speak>
<!--
Speak the Channel Report header information.
The male voice "announces" the type of data to be read by the female voice.
-->
  <voice gender="male" variant="7">
    <p>
      <s>Report Name:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%REPORT-NAME%}</s>
    </p>
  </voice>
  <voice gender="male" variant="7">
    <p>
      <s>Report Description:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%REPORT-DESCRIPTION%}</s>
    </p>
  </voice>
  <voice gender="male" variant="7">
    <p>
      <s>Report Generation Date and Time:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%REPORT-TIME% format="%A, %B %d %Y"}</s>
    </p>
  </voice>

<!--
Tell the listener in what order the feeds items will be read.
-->
{%?GROUP-ITEMS-BY-CHANNEL%}
  <voice gender="female" variant="1">
    <p>
      <s>Feed items are grouped by channels</s>
    </p>
  </voice>
{%ELSE%}
  <voice gender="female" variant="1">
    <p>
      <s>Feed items are in descending date order</s>
    </p>
  </voice>
{%ENDIF%}

<!--
Speak the Channel Report header information.
The male voice "announces" the type of data to be read by the female voice.
-->
{%REPEAT% FeedItems}
  <voice gender="male" variant="7">
    <p>
      <s>Feed Item Title:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%ITEM-METADATA% name!}</s>
    </p>
  </voice>
  <voice gender="male" variant="7">
    <p>
      <s>From Channel:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%CHANNEL-METADATA% name}</s>
    </p>
  </voice>

{%?ITEM-METADATA% author}
  <voice gender="male" variant="7">
    <p>
      <s>Authored by:</s>
    </p>
  </voice>{%REPEAT% author insert=, }
  <voice gender="female" variant="1">
    <p>
      <s>{%ITEM-METADATA% author}{%/REPEAT%}</s>
    </p>
  </voice>
{%ENDIF%}
  
  <voice gender="male" variant="7">
    <p>
      <s>Feed Item Content:</s>
    </p>
  </voice>
  <voice gender="female" variant="1">
    <p>
      <s>{%ITEM-METADATA% description encode=percent}</s>
    </p>
  </voice>

{%/REPEAT%}
</speak>

Post-processing command

Here's the part where we transform the SSML file to a .WAV audio file.

python "path_to\espeak.py"

Post-processing Python script "espeak.py"

import _winreg
import shlex
import subprocess
import win32api

# Constants...
eSpeakRegKey = "HKEY_CLASSES_ROOT\\TypeLib\\{7192AA2F-F759-43E9-91E7-226371EF6B2F}\\1.0\\HELPDIR"
# HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak\\Path
# HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\eSpeak_is1\\InstallLocation

reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\eSpeak_is1")
print _winreg.QueryValue(reg, "DisplayName")
quit()

eSpeakPath = "'C:\\Program Files\\eSpeak\\command_line\\espeak.exe' -k20 -m -f 'E:\MyAwasuData\Reports\eSpeak_SSML.xml' -w 'E:\MyAwasuData\Reports\eSpeak_SSML.wav'"
eSpeakCmd = ""
eSpeakList = ["C:\\Program Files\\eSpeak\\command_line\\espeak.exe", "-k20", "-m", "-f", "E:\MyAwasuData\Reports\eSpeak_SSML.xml", "-w", "E:\MyAwasuData\Reports\eSpeak_SSML.wav"]

# args = shlex.split(eSpeakList)
# print args

try:
    p = subprocess.Popen(eSpeakList) # Success!
except WindowsError as (errno, strerror):
    print "Error #" + str(errno) + " - " + strerror