Example #1
0
 def __init__(self,
              langdb,
              phonedb,
              dictcodec='euc-jp',
              framerate=44100,
              ratio=1.0 / 32768.0,
              restdur=200):
     self.yomer = Yomer(langdb, dictcodec)
     self.wakacher = Wakacher(langdb, dictcodec)
     self.phonedb = phonedb
     self.framerate = framerate
     self.restframe = framerate * restdur / 1000
     self.ratio = ratio
     return
Example #2
0
 def __init__(self, langdb, phonedb,
              dictcodec='euc-jp', framerate=44100, ratio=1.0/32768.0):
     self.yomer = Yomer(langdb, dictcodec)
     self.wakacher = Wakacher(langdb, dictcodec)
     self.phonedb = phonedb
     self.framerate = framerate
     self.ratio = ratio
     return
Example #3
0
class Synthesizer(object):

    def __init__(self, langdb, phonedb,
                 dictcodec='euc-jp', framerate=44100, ratio=1.0/32768.0):
        self.yomer = Yomer(langdb, dictcodec)
        self.wakacher = Wakacher(langdb, dictcodec)
        self.phonedb = phonedb
        self.framerate = framerate
        self.ratio = ratio
        return

    def synth(self, writer, text):
        self._genwave(writer, self._genphones(text))
        return

    def _genphones(self, text):
        k0 = '_'
        for s in self.wakacher.get_chunks(text):
            for y in self.yomer.get_yomi(s):
                for (k,v) in y:
                    for m in MoraTable.parse(v or k):
                        if m.name == '-':
                            k = k0
                        elif m.name == 'q':
                            k = k0+m.name
                            k0 = '_'
                        else:
                            k = k0+m.name
                            k0 = m.name[-1:]
                        yield k
                    yield k0+'_'
        return

    def _genwave(self, writer, keys):
        (f0, w0, k0) = (None, 0, None)
        for k1 in keys:
            try:
                data = self.phonedb[k1]
            except KeyError:
                continue
            a = array.array('h')
            a.fromstring(data)
            f1 = [ x*self.ratio for x in a ]
            w1 = 0
            if k0 is not None:
                k = k0+'+'+k1
                if k in self.phonedb:
                    (w1,) = struct.unpack('<i', self.phonedb[k])
                if w1:
                    writer.write(f0[w0:-w1])
                    writer.write(mix(f0[-w1:], f1[:w1]))
                else:
                    writer.write(f0[w0:])                    
            (f0,w0,k0) = (f1,w1,k1)
        if f0 is not None:
            writer.write(f0[w0:])
        return
Example #4
0
class Synthesizer(object):
    def __init__(self,
                 langdb,
                 phonedb,
                 dictcodec='euc-jp',
                 framerate=44100,
                 ratio=1.0 / 32768.0,
                 restdur=200):
        self.yomer = Yomer(langdb, dictcodec)
        self.wakacher = Wakacher(langdb, dictcodec)
        self.phonedb = phonedb
        self.framerate = framerate
        self.restframe = framerate * restdur / 1000
        self.ratio = ratio
        return

    def synth(self, writer, text):
        self.genwave(writer, self._genphones(text))
        return

    VOWELS = ('aa', 'ii', 'uu', 'ee', 'oo', 'nn')

    def _genphones(self, text):
        for s in self.wakacher.get_chunks(text):
            for y in self.yomer.get_yomi(s):
                for (k, v) in y:
                    k0 = '_'
                    for m in MoraTable.parse(v or k):
                        if m.name in ('.', ','):
                            yield k0 + '_'
                            k = m.name
                            k0 = '_'
                        elif m.name == '-':
                            k = k0
                        elif m.name == 'q':
                            k = k0 + m.name
                            k0 = '_'
                        else:
                            k = k0 + m.name
                            k0 = m.name[-1]
                            if k in self.VOWELS:
                                k = k[0]
                        yield k
                    yield k0 + '_'
        return

    def genwave(self, writer, keys):
        (f0, w0, k0) = (None, 0, None)
        for k1 in keys:
            if k1 == '.':
                f1 = [0] * (self.restframe * 2)
            elif k1 == ',':
                f1 = [0] * (self.restframe)
            else:
                try:
                    data = self.phonedb[k1]
                except KeyError:
                    continue
                a = array.array('h')
                a.fromstring(data)
                f1 = [x * self.ratio for x in a]
            w1 = 0
            if k0 is not None:
                k = k0 + '+' + k1
                if k in self.phonedb:
                    (w1, ) = struct.unpack('<i', self.phonedb[k])
                if w1:
                    writer.write(f0[w0:-w1])
                    writer.write(mix(f0[-w1:], f1[:w1]))
                else:
                    writer.write(f0[w0:])
            (f0, w0, k0) = (f1, w1, k1)
        if f0 is not None:
            writer.write(f0[w0:])
        return