Example #1
0
    def __init__(self):
        # class variables
        localeHelper = LocaleHelper('en_EN')
        self.locale = localeHelper.getLocale()
        self.recording_time = 5
        self.player_pause = 'undefine'
        self.player_play = 'undefine'
        self.dictation = False
        self.config = expanduser('~')+'/.config/google2ubuntu/google2ubuntu.conf'
        
        # looking for the configuration file
        self.__loadconfig()
        
        # build the window
        self.w = Gtk.Window()
        self.w.set_title(_("Setup window"))
        self.w.set_resizable(False)     
        self.w.get_focus()
        self.w.set_position(Gtk.WindowPosition.CENTER)      
        self.w.set_default_size(80,80)  
        self.w.set_border_width(5)
        self.w.set_hexpand(True)
        self.w.set_vexpand(True)

        # add the grid to the window        
        grid = self.__getGrid()
        self.w.add(grid)
        self.w.show_all()
Example #2
0
    def __init__(self, key):
        # make the program able to switch language
        self.p = os.path.dirname(os.path.abspath(__file__)).strip('librairy')

        localeHelper = LocaleHelper('en_EN')

        self.lang = localeHelper.getLocale()
        # this line can be remove if we modify the config/en_EN to config/en
        #self.lang = self.lang+'_'+self.lang.upper()

        # Initialisation des notifications
        self.PID = str(os.getpid())
        os.system('rm /tmp/g2u_*_'+self.PID+' 2>/dev/null')
        os.system('python '+self.p+'librairy/osd.py '+self.PID+' &')

        # on joue un son pour signaler le démarrage
        os.system('play '+self.p+'resources/sound.wav &')
        os.system('> /tmp/g2u_start_'+self.PID)

        # On lance le script d'enregistrement pour acquérir la voix pdt 5s
        command =self.p+'record.sh ' + self.PID
        p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
        output,error  = p.communicate()
        # return to 16kHz
        os.system(self.p+'convert.sh '+self.PID)
        self.sendto(key)
Example #3
0
    def __init__(self, key):
        # make the program able to switch language
        self.p = os.path.dirname(os.path.abspath(__file__)).strip('librairy')

        localeHelper = LocaleHelper('en_EN')

        self.lang = localeHelper.getLocale()
        # this line can be remove if we modify the config/en_EN to config/en
        #self.lang = self.lang+'_'+self.lang.upper()

        # Initialisation des notifications
        self.PID = str(os.getpid())
        os.system('rm /tmp/g2u_*_' + self.PID + ' 2>/dev/null')
        os.system('python ' + self.p + 'librairy/osd.py ' + self.PID + ' &')

        # on joue un son pour signaler le démarrage
        os.system('play ' + self.p + 'resources/sound.wav &')
        os.system('> /tmp/g2u_start_' + self.PID)

        # On lance le script d'enregistrement pour acquérir la voix pdt 5s
        command = self.p + 'record.sh ' + self.PID
        p = subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             shell=True)
        output, error = p.communicate()
        # return to 16kHz
        os.system(self.p + 'convert.sh ' + self.PID)
        self.sendto(key)
Example #4
0
    def __init__(self, text):
        # need to put this line
        locale.setlocale(locale.LC_ALL, '')

        # make the program able to switch language
        p = os.path.dirname(os.path.abspath(__file__)).strip('librairy')
        localeHelper = LocaleHelper()
        lc = localeHelper.getLocale()
        text = unicodedata.normalize('NFKD', unicode(text, "utf-8"))
        text = text.encode("utf8")
        text = text.replace('\n', ' ')
        text_list = re.split('(\,|\.)', text)
        combined_text = []
        output = open('/tmp/tts.mp3', "w")

        for idx, val in enumerate(text_list):
            if idx % 2 == 0:
                combined_text.append(val)
            else:
                joined_text = ''.join((combined_text.pop(), val))
                if len(joined_text) < 100:
                    combined_text.append(joined_text)
                else:
                    subparts = re.split('( )', joined_text)
                    temp_string = ""
                    temp_array = []
                    for part in subparts:
                        temp_string = temp_string + part
                        if len(temp_string) > 80:
                            temp_array.append(temp_string)
                            temp_string = ""
                    #append final part
                    temp_array.append(temp_string)
                    combined_text.extend(temp_array)
        #download chunks and write them to the output file
        for idx, val in enumerate(combined_text):
            mp3url = "http://translate.google.com/translate_tts?ie=UTF-8&tl=%s&q=%s&total=%s&idx=%s" % (
                lc, urllib.quote(val), len(combined_text), idx)
            headers = {
                "Host":
                "translate.google.com",
                "Referer":
                "http://www.gstatic.com/translate/sound_player2.swf",
                "User-Agent":
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.163 Safari/535.19"
            }
            req = urllib2.Request(mp3url, '', headers)
            sys.stdout.write('.')
            sys.stdout.flush()
            if len(val) > 0:
                try:
                    response = urllib2.urlopen(req)
                    output.write(response.read())
                    time.sleep(.5)
                except urllib2.HTTPError as e:
                    print('%s' % e)
        output.close()

        os.system("play /tmp/tts.mp3 &")
    def do_activate(self):
        win = MainWindow(self)
        win.show_all()
        localeHelper = LocaleHelper()
        lang = localeHelper.getLocale()

        t=gettext.translation('google2ubuntu',os.path.dirname(os.path.abspath(__file__))+'/i18n/',languages=[lang])
        t.install()
Example #6
0
    def __init__(self,text):
        # need to put this line 
        locale.setlocale(locale.LC_ALL, '')

        # make the program able to switch language
        p = os.path.dirname(os.path.abspath(__file__)).strip('librairy')   
        localeHelper = LocaleHelper()
        lc = localeHelper.getLocale()
        text = unicodedata.normalize('NFKD', unicode(text,"utf-8"))
        text=text.encode("utf8")
        text = text.replace('\n',' ')
        text_list = re.split('(\,|\.)', text)
        combined_text = []
        output=open('/tmp/tts.mp3',"w")
        
        for idx, val in enumerate(text_list):
            if idx % 2 == 0:
                combined_text.append(val)
            else:
                joined_text = ''.join((combined_text.pop(),val))
                if len(joined_text) < 100:
                    combined_text.append(joined_text)
                else:
                    subparts = re.split('( )', joined_text)
                    temp_string = ""
                    temp_array = []
                    for part in subparts:
                        temp_string = temp_string + part
                        if len(temp_string) > 80:
                            temp_array.append(temp_string)
                            temp_string = ""
                    #append final part
                    temp_array.append(temp_string)
                    combined_text.extend(temp_array)
        #download chunks and write them to the output file
        for idx, val in enumerate(combined_text):
            mp3url = "http://translate.google.com/translate_tts?ie=UTF-8&tl=%s&q=%s&total=%s&idx=%s" % (lc, urllib.quote(val), len(combined_text), idx)
            print mp3url
            headers = {"Host":"translate.google.com",
            "Referer":"http://www.gstatic.com/translate/sound_player2.swf",
            "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.163 Safari/535.19"}
            req = urllib2.Request(mp3url, '', headers)
            sys.stdout.write('.')
            sys.stdout.flush()
            if len(val) > 0:
                try:
                    response = urllib2.urlopen(req)
                    output.write(response.read())
                    time.sleep(.5)
                except urllib2.HTTPError as e:
                    print ('%s' % e)
        output.close()


        os.system("play /tmp/tts.mp3 &")
Example #7
0
    def do_activate(self):
        win = MainWindow(self)
        win.show_all()
        localeHelper = LocaleHelper()
        lang = localeHelper.getLocale()

        t = gettext.translation('google2ubuntu',
                                os.path.dirname(os.path.abspath(__file__)) +
                                '/i18n/',
                                languages=[lang])
        t.install()
Example #8
0
    def populate_store(self, store):
        """
        @description: load the treeview from the google2ubuntu.xml file or
        from the default.xml file
        
        @param: store
            the listStore that will be modify
        """
        # user ocnfig file
        config = expanduser('~') + '/.config/google2ubuntu/google2ubuntu.xml'

        # default config file for the selected language
        path = os.path.dirname(os.path.abspath(__file__)).strip('librairy')
        localeHelper = LocaleHelper('en_EN')
        self.lang = localeHelper.getLocale()
        default = path + 'config/' + self.lang + '/default.xml'

        try:
            if os.path.isfile(config):
                # here the program refuses to load the xml file
                tree = ET.parse(config)
            else:
                if os.path.exists(expanduser('~') +
                                  '/.config/google2ubuntu') == False:
                    os.makedirs(expanduser('~') + '/.config/google2ubuntu')
                tree = ET.parse(default)
            if os.path.exists(
                    expanduser('~') +
                    '/.config/google2ubuntu/modules') == False:
                os.system('cp -r ' + path + '/modules ' + expanduser('~') +
                          '/.config/google2ubuntu')

            root = tree.getroot()
            for entry in root.findall('entry'):
                Type = entry.get('name')
                Key = entry.find('key').text
                Command = entry.find('command').text
                linker = entry.find('linker').text
                spacebyplus = entry.find('spacebyplus').text
                store.append([Key, Command, Type, linker, spacebyplus])
        except Exception as e:
            print 'Error while reading config file'
            print type(e)
            print e.args
            print e
Example #9
0
    def populate_store(self, store):    
        """
        @description: load the treeview from the google2ubuntu.xml file or
        from the default.xml file
        
        @param: store
            the listStore that will be modify
        """    
        # user ocnfig file
        config = expanduser('~') +'/.config/google2ubuntu/google2ubuntu.xml'
        
        # default config file for the selected language
        path = os.path.dirname(os.path.abspath(__file__)).strip('librairy')    
        localeHelper = LocaleHelper('en_EN')
        lang = localeHelper.getLocale()
        # this line can be remove if we change config/en_EN to config/en
        #lang = lang+'_'+lang.upper()
        
        default = path +'config/'+lang+'/default.xml'        

        try:
            if os.path.isfile(config):
                # here the program refuses to load the xml file
                tree = ET.parse(config)
            else:
                if os.path.exists(expanduser('~') +'/.config/google2ubuntu') == False:
                    os.makedirs(expanduser('~') +'/.config/google2ubuntu')
                    os.system('cp -r /usr/share/google2ubuntu/modules '+expanduser('~') +'/.config/google2ubuntu')    
                
                tree = ET.parse(default)
            
            root = tree.getroot()
            for entry in root.findall('entry'):
                Type=entry.get('name')
                Key=entry.find('key').text
                Command=entry.find('command').text
                store.append([Key, Command, Type])  
        except Exception as e:
            print 'Error while reading config file'
            print type(e)
            print e.args
            print e
Example #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Notify
from os.path import expanduser
from localehelper import LocaleHelper
import time, os, gettext, sys, locale

path = os.path.dirname(os.path.abspath(__file__)).strip('librairy')
localeHelper = LocaleHelper()
lang = localeHelper.getLocale()
t=gettext.translation('google2ubuntu',path+'i18n/',languages=[lang])
t.install()

#keep the old way for the moment
#gettext.install('google2ubuntu',path+'/i18n/')
RESULT = False
path += 'resources'


if len(sys.argv) >= 2:
    PID = sys.argv[1]
    # nom des fichiers
    start='/tmp/g2u_start_'+PID
    stop='/tmp/g2u_stop_'+PID
    result='/tmp/g2u_result_'+PID
    cmd='/tmp/g2u_cmd_'+PID
    error='/tmp/g2u_error_'+PID
    display='/tmp/g2u_display_'+PID
Example #11
0
    def __init__(self, button_back):
        # class variables
        localeHelper = LocaleHelper("en_EN")
        self.locale = localeHelper.getLocale()
        self.recording_time = 5
        self.player_pause = ""
        self.player_play = ""
        self.dictation = False
        self.config = expanduser("~") + "/.config/google2ubuntu/google2ubuntu.conf"
        self.threshold = 5
        self.hotword = "ok start"

        # looking for the configuration file
        self.__loadconfig()

        label1 = Gtk.Label(_("Select your language"))
        label1.set_justify(Gtk.Justification.LEFT)
        label1.set_halign(Gtk.Align.START)
        label2 = Gtk.Label(_("Set the recording time (seconds)"))
        label2.set_justify(Gtk.Justification.LEFT)
        label2.set_halign(Gtk.Align.START)
        label3 = Gtk.Label(_("Set the music player's play command"))
        label3.set_justify(Gtk.Justification.LEFT)
        label3.set_halign(Gtk.Align.START)
        label4 = Gtk.Label(_("Set the music player's pause command"))
        label4.set_justify(Gtk.Justification.LEFT)
        label4.set_halign(Gtk.Align.START)
        label5 = Gtk.Label(_("Hotword mode"))
        label5.set_justify(Gtk.Justification.LEFT)
        label5.set_halign(Gtk.Align.START)
        label6 = Gtk.Label(_("Set the noise threshold"))
        label6.set_justify(Gtk.Justification.LEFT)
        label6.set_halign(Gtk.Align.START)
        label7 = Gtk.Label(_("Set the hotword"))
        label7.set_justify(Gtk.Justification.LEFT)
        label7.set_halign(Gtk.Align.START)

        combo = self.__get_combobox()

        self.scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1, 10, 1)
        self.scale.set_value(self.recording_time)
        self.scale.connect("value-changed", self.scale_moved)
        self.scale.set_tooltip_text(_("Change the recording time"))

        self.entry1 = Gtk.Entry()
        self.entry1.set_text(self.player_play)
        self.entry1.set_tooltip_text(_("Set the play command"))

        self.entry2 = Gtk.Entry()
        self.entry2.set_text(self.player_pause)
        self.entry2.set_tooltip_text(_("Set the pause command"))

        switch_active = Gtk.Switch()
        switch_active.set_active(False)
        if os.path.exists("/tmp/hotword"):
            switch_active.set_active(True)

        switch_active.set_tooltip_text(_("Put the hotword mode ON or OFF"))
        switch_active.connect("notify::active", self.active_hotword)

        self.scale_threshold = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1, 20, 0.5)
        self.scale_threshold.set_value(self.threshold)
        self.scale_threshold.connect("value-changed", self.threshold_changed)
        self.scale_threshold.set_tooltip_text(_("Set the sound level in % under which sound is considerated as noise"))

        self.entry3 = Gtk.Entry()
        self.entry3.set_text(self.hotword)
        self.entry3.set_tooltip_text(_("Set the hotword to start effective recording"))

        # button_back = Gtk.Button.new_from_stock(Gtk.STOCK_OK)
        button_back.connect("clicked", self.on_clicked)

        # an invisble widget to fill the window
        ll = Gtk.Label()
        ll.set_vexpand(True)

        self.grid = Gtk.Grid()
        self.grid.set_border_width(10)
        self.grid.set_row_spacing(15)
        self.grid.set_vexpand(True)
        self.grid.set_column_spacing(5)
        self.grid.set_column_homogeneous(True)
        self.grid.attach(label1, 0, 0, 4, 1)
        self.grid.attach(combo, 4, 0, 2, 1)
        self.grid.attach(label2, 0, 1, 4, 1)
        self.grid.attach(self.scale, 4, 1, 2, 1)
        self.grid.attach(label3, 0, 2, 4, 1)
        self.grid.attach(self.entry1, 4, 2, 2, 1)
        self.grid.attach(label4, 0, 3, 4, 1)
        self.grid.attach(self.entry2, 4, 3, 2, 1)
        self.grid.attach(label5, 0, 4, 5, 1)
        self.grid.attach(switch_active, 5, 4, 1, 1)
        self.grid.attach(label7, 0, 5, 4, 1)
        self.grid.attach(self.entry3, 4, 5, 2, 1)
        self.grid.attach(label6, 0, 6, 4, 1)
        self.grid.attach(self.scale_threshold, 4, 6, 2, 1)
        self.grid.attach(ll, 0, 7, 6, 1)
        self.grid.attach(button_back, 5, 8, 1, 1)
Example #12
0
    def __init__(self, button_back, button_cancel):
        # class variables
        localeHelper = LocaleHelper('en_EN')
        self.locale = localeHelper.getLocale()
        self.recording_time = 5
        self.player_pause = ''
        self.player_play = ''
        self.dictation = False
        self.config = expanduser(
            '~') + '/.config/google2ubuntu/google2ubuntu.conf'
        self.threshold = 5
        self.hotword = _('ok start')

        # looking for the configuration file
        self.__loadconfig()

        label1 = Gtk.Label(_('Select your language'))
        label1.set_justify(Gtk.Justification.LEFT)
        label1.set_halign(Gtk.Align.START)
        label1.set_hexpand(True)
        label2 = Gtk.Label(_('Set the recording time (seconds)'))
        label2.set_justify(Gtk.Justification.LEFT)
        label2.set_halign(Gtk.Align.START)
        label3 = Gtk.Label(_("Set the music player's play command"))
        label3.set_justify(Gtk.Justification.LEFT)
        label3.set_halign(Gtk.Align.START)
        label4 = Gtk.Label(_("Set the music player's pause command"))
        label4.set_justify(Gtk.Justification.LEFT)
        label4.set_halign(Gtk.Align.START)
        label5 = Gtk.Label(_('Hotword mode'))
        label5.set_justify(Gtk.Justification.LEFT)
        label5.set_halign(Gtk.Align.START)
        label6 = Gtk.Label(_('Set the noise threshold'))
        label6.set_justify(Gtk.Justification.LEFT)
        label6.set_halign(Gtk.Align.START)
        label7 = Gtk.Label(_('Set the hotword'))
        label7.set_justify(Gtk.Justification.LEFT)
        label7.set_halign(Gtk.Align.START)

        combo = self.__get_combobox()

        self.scale = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 1,
                                              10, 1)
        self.scale.set_value(self.recording_time)
        self.scale.connect("value-changed", self.scale_moved)
        self.scale.set_tooltip_text(_('Change the recording time'))

        self.entry1 = Gtk.Entry()
        self.entry1.set_text(self.player_play)
        self.entry1.set_tooltip_text(_('Set the play command'))

        self.entry2 = Gtk.Entry()
        self.entry2.set_text(self.player_pause)
        self.entry2.set_tooltip_text(_('Set the pause command'))

        switch_active = Gtk.Switch()
        switch_active.set_active(False)
        switch_active.set_hexpand(False)
        if os.path.exists('/tmp/hotword'):
            switch_active.set_active(True)

        switch_active.set_tooltip_text(_('Put the hotword mode ON or OFF'))
        switch_active.connect("notify::active", self.active_hotword)

        self.scale_threshold = Gtk.Scale.new_with_range(
            Gtk.Orientation.HORIZONTAL, 1, 20, 0.5)
        self.scale_threshold.set_value(self.threshold)
        self.scale_threshold.connect("value-changed", self.threshold_changed)
        self.scale_threshold.set_tooltip_text(
            _('Set the sound level in % under which sound is considerated as noise'
              ))

        self.entry3 = Gtk.Entry()
        self.entry3.set_text(self.hotword)
        self.entry3.set_tooltip_text(
            _('Set the hotword to start effective recording'))

        button_back.connect("clicked", self.on_clicked)

        # an invisble widget to fill the window
        ll = Gtk.Label()
        ll.set_vexpand(True)

        self.grid = Gtk.Grid()
        self.grid.set_border_width(10)
        self.grid.set_row_spacing(15)
        self.grid.set_vexpand(True)
        self.grid.set_hexpand(True)
        self.grid.set_column_spacing(2)
        self.grid.set_column_homogeneous(False)
        self.grid.attach(label1, 0, 0, 14, 1)
        self.grid.attach(combo, 14, 0, 1, 1)
        self.grid.attach(label2, 0, 1, 11, 1)
        self.grid.attach(self.scale, 11, 1, 4, 1)
        self.grid.attach(label3, 0, 2, 11, 1)
        self.grid.attach(self.entry1, 11, 2, 4, 1)
        self.grid.attach(label4, 0, 3, 11, 1)
        self.grid.attach(self.entry2, 11, 3, 4, 1)
        self.grid.attach(label5, 0, 4, 14, 1)
        self.grid.attach(switch_active, 14, 4, 1, 1)
        self.grid.attach(label7, 0, 5, 11, 1)
        self.grid.attach(self.entry3, 11, 5, 4, 1)
        self.grid.attach(label6, 0, 6, 11, 1)
        self.grid.attach(self.scale_threshold, 11, 6, 4, 1)
        self.grid.attach(ll, 0, 7, 15, 1)
        self.grid.attach(button_cancel, 13, 8, 1, 1)
        self.grid.attach(button_back, 14, 8, 1, 1)