The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.

This URL has Read-Only access.

Statistics
| Revision:

root / trunk / DomotiGa / VoiceText.module @ 256

History | View | Annotate | Download (3.5 kB)

1
' Gambas module file
2
3
' Description:
4
' VoiceText.module
5
' Support for VoiceText, Cepstral's Swift, and espeak.
6
7
' Development Status:
8
' Not implemented completely, but it works.
9
10
' DomotiGa - an open source home automation program.
11
' Copyright(C) 2008-2009 Ron Klinkien
12
13
' Read file called COPYING for license details.
14
15
PRIVATE sOutput AS String
16
17
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
' speak text with voice
19
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
PUBLIC SUB Speak(sText AS String, OPTIONAL sSex AS String)
21
22
  DIM sVoiceSex AS String
23
24
  ' audio mute is enabled
25
  IF Main.GlobalVar["Mute"] THEN
26
    Main.WriteSpeakLog(("[Muted] '") & sText & "'")
27
  ELSE
28
    ' speak out loud
29
    Main.WriteSpeakLog("'" & sText & "'")
30
    IF Main.bVoiceTextEnabled AND Main.sVoiceTextEngine = "cepstral" THEN
31
      IF sSex THEN
32
        SELECT CASE sSex
33
          CASE "female"
34
            sVoiceSex = PickVoice(Main.sVoiceTextVoicesFemale)
35
          CASE "male"
36
            sVoiceSex = PickVoice(Main.sVoiceTextVoicesMale)
37
          CASE ELSE
38
            sVoiceSex = sSex
39
        END SELECT
40
      ELSE
41
        sVoiceSex = PickVoice(Main.sVoiceTextVoicesFemale)
42
      END IF
43
44
      ' Swift command-line synthesis program
45
      ' Version 5.1.0 of July 2008
46
      ' Copyright (c) 2000-2006, Cepstral LLC.
47
48
      ' Voice      | Version | Lic? | Gender | Age | Language         | Sample Rate
49
      ' -----------|---------|------|--------|-----|------------------|------------
50
      ' Linda      | 5.1.0   | Yes  | female | 25  | US English       | 16000 Hz
51
      ' Emily      | 5.1.0   | Yes  | female | 30  | US English       | 16000 Hz
52
53
      ' swift -n voice 'text to speak'
54
55
      IF NOT Main.sVoiceTextPrefixCmd THEN
56
        EXEC ["swift", "-n", sVoiceSex, "'" & sText & "'"] FOR READ AS "Speaking"
57
      ELSE
58
        EXEC [Main.sVoiceTextPrefixCmd, "swift", "-n", sVoiceSex, "'" & sText & "'"] FOR READ AS "Speaking"
59
      END IF
60
    ELSE IF Main.bVoiceTextEnabled AND Main.sVoiceTextEngine = "espeak" THEN
61
      ' espeak -v voice 'text to speak'
62
      IF NOT Main.sVoiceTextPrefixCmd THEN
63
        EXEC ["espeak", "-v", Main.sVoiceTextVoicesMale, "'" & sText & "'"] FOR READ AS "Speaking"
64
      ELSE
65
        EXEC [Main.sVoiceTextPrefixCmd, "espeak", "-v", Main.sVoiceTextVoicesMale, "'" & sText & "'"] FOR READ AS "Speaking"
66
      END IF
67
    END IF
68
  END IF
69
70
END
71
72
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73
' got output, save it
74
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75
PUBLIC SUB Speaking_Read()
76
77
  DIM sLine AS String
78
79
  READ #LAST, sLine, -256
80
  sOutput &= sLine
81
82
END
83
84
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85
' catch errors
86
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
PUBLIC SUB Speaking_Error(sString AS String)
88
89
  Main.WriteDebugLog("[VoiceText] " & Replace$(sString, "\n", ""))
90
91
END
92
93
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
' speak command finished
95
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
PUBLIC SUB Speaking_Kill()
97
98
  IF Main.bVoiceTextDebug AND sOutput THEN Main.WriteDebugLog("[VoiceText] " & sOutput)
99
100
END
101
102
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
' select voice to use
104
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105
PUBLIC FUNCTION PickVoice(sVoices AS String) AS String
106
107
  DIM aVoices AS String[]
108
  DIM sVoice AS String
109
110
  ' split them up if more than one voice is specified
111
  aVoices = Split(sVoices, ",")
112
  IF aVoices.Count > 1 THEN
113
    ' pick a random one ourselfs
114
    RETURN aVoices[Rnd(aVoices.Count)]
115
  ELSE
116
    RETURN sVoices
117
  END IF
118
119
END