Skip to content

Commit

Permalink
Merge pull request #12 from thiagohersan/master
Browse files Browse the repository at this point in the history
language detection
  • Loading branch information
thiagohersan committed Jul 12, 2013
2 parents 301c383 + 1b77e8f commit d5ade83
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions megavoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import sys, time, subprocess
sys.path.append("../LocalNet")
from interfaces import PrototypeInterface, runPrototype
import langid

FESTIVAL_ES = "voice_cstr_upc_upm_spanish_hts"
FESTIVAL_EN = "voice_cstr_upc_upm_spanish_hts"
FESTIVAL_EN = "voice_kal_diphone"
FESTIVALBIN = "./festival"
FESTIVALCMD = "echo \"(LANG) (SayText \\\"XXXXX\\\")\" | "

Expand All @@ -28,24 +29,28 @@ def setup(self):
self.lastQueueCheck = time.time()
## turn up the volume
subprocess.call("amixer set PCM -- -0", shell=True)

## for language identification
langid.set_languages(['en','es'])
def loop(self):
## check state
if ((not self.messageQ.empty()) and
(time.time() - self.lastQueueCheck > self.queueDelay)):
(locale,type,txt) = self.messageQ.get()
## TODO: detect language!

## detect language!
mLanguage = FESTIVAL_ES if(langid.classify(txt)[0] == 'es') else FESTIVAL_EN

## then remove accents and nonAscii characters
txt = self.removeNonAscii(self.removeAccents(txt.encode('utf-8')))
toSay = (FESTIVALCMD+FESTIVALBIN).replace("LANG",FESTIVAL_ES)
toSay = (FESTIVALCMD+FESTIVALBIN).replace("LANG",mLanguage)
toSay = toSay.replace("XXXXX",txt)
subprocess.call(toSay, shell=True)
self.lastQueueCheck = time.time()
if(self.messageQ.qsize() > 50):
self.queueDelay = 10
elif(self.messageQ.qsize() > 10):
self.queueDelay = 20
self.queueDelay = 1
else:
self.queueDelay = 30
self.queueDelay = 5

if __name__=="__main__":
## TODO: get ip and ports from command line
Expand Down

0 comments on commit d5ade83

Please sign in to comment.