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 @ 2

History | View | Annotate | Download (2.8 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 Ron Klinkien
12
13
' Read file called LICENSE for license details.
14
15
PRIVATE sOutput AS String
16
17
PUBLIC SUB Speak(sText AS String, OPTIONAL sSex AS String)
18
19
  DIM sVoiceSex AS String
20
21
  IF Main.GlobalVar["Mute"] THEN
22
    Main.WriteSpeakLog("[Muted] '" & sText & "'")
23
  ELSE
24
    Main.WriteSpeakLog("'" & sText & "'")
25
    IF Main.bVoiceTextEnabled AND Main.sVoiceTextEngine = "cepstral" THEN
26
      IF sSex THEN
27
        SELECT CASE sSex
28
          CASE "female"
29
            sVoiceSex = PickVoice(Main.sVoiceTextVoicesFemale)
30
          CASE "male"
31
            sVoiceSex = PickVoice(Main.sVoiceTextVoicesMale)
32
          CASE ELSE
33
            sVoiceSex = sSex
34
        END SELECT
35
      ELSE
36
        sVoiceSex = PickVoice(Main.sVoiceTextVoicesFemale)
37
      END IF
38
39
      ' Swift command-line synthesis program
40
      ' Version 5.1.0 of July 2008
41
      ' Copyright (c) 2000-2006, Cepstral LLC.
42
43
      ' Voice      | Version | Lic? | Gender | Age | Language         | Sample Rate
44
      ' -----------|---------|------|--------|-----|------------------|------------
45
      ' Linda      | 5.1.0   | Yes  | female | 25  | US English       | 16000 Hz
46
      ' Emily      | 5.1.0   | Yes  | female | 30  | US English       | 16000 Hz
47
48
      ' swift -n voice 'text to speak'
49
50
      IF NOT Main.sVoiceTextPrefixCmd THEN
51
        EXEC ["swift", "-n", sVoiceSex, "'" & sText & "'"] FOR READ AS "Speaking"
52
      ELSE
53
        EXEC [Main.sVoiceTextPrefixCmd, "swift", "-n", sVoiceSex, "'" & sText & "'"] FOR READ AS "Speaking"
54
      END IF
55
    ELSE IF Main.bVoiceTextEnabled AND Main.sVoiceTextEngine = "espeak" THEN
56
      ' espeak -v voice 'text to speak'
57
      IF NOT Main.sVoiceTextPrefixCmd THEN
58
        EXEC ["espeak", "-v", Main.sVoiceTextVoicesMale, "'" & sText & "'"] FOR READ AS "Speaking"
59
      ELSE
60
        EXEC [Main.sVoiceTextPrefixCmd, "espeak", "-v", Main.sVoiceTextVoicesMale, "'" & sText & "'"] FOR READ AS "Speaking"
61
      END IF
62
    END IF
63
  END IF
64
65
END
66
67
PUBLIC SUB Speaking_Read()
68
69
  DIM sLine AS String
70
71
  READ #LAST, sLine, -256
72
  sOutput &= sLine
73
74
END
75
76
PUBLIC SUB Speaking_Error(sString AS String)
77
78
  Main.WriteDebugLog("[VoiceText] " & Replace$(sString, "\n", ""))
79
80
END
81
82
PUBLIC SUB Speaking_Kill()
83
84
  IF Main.bVoiceTextDebug AND sOutput THEN Main.WriteDebugLog("[VoiceText] " & sOutput)
85
86
END
87
88
PUBLIC SUB PickVoice(sVoices AS String) AS String
89
90
  DIM aVoices AS String[]
91
  DIM sVoice AS String
92
93
  ' split them up if more than one voice is specified
94
  aVoices = Split(sVoices, ",")
95
  IF aVoices.Count > 1 THEN
96
    ' pick a random one ourselfs
97
    RETURN aVoices[Rnd(aVoices.Count)]
98
  ELSE
99
    RETURN sVoices
100
  END IF
101
102
END