Browse Source

Set up DB object and some child classes. Started loading some stuff from the DB

master
hadware 6 years ago
parent
commit
9f1146535e
  1. 69
      db_reader.py

69
db_reader.py

@ -0,0 +1,69 @@
import argparse
from dataclasses import dataclass
from pathlib import Path
from typing import List, Tuple
MBROLA_VOICES_FOLDER = Path("/usr/share/mbrola/")
argparser = argparse.ArgumentParser()
argparser.add_argument("mbrola_db", type=Path,
help="Mrbola db name or direct path")
PhonemeCode = int
@dataclass
class DiphoneInfo:
left: PhonemeCode
right: PhonemeCode
pos_wave: int # position in SPEECH_FILE
halfseg: int # position of center of diphone
pos_pm: int # index in PITCHMARK_FILE
nb_frame: int # Number of pitch markers
@dataclass
class FrameType:
pass
@dataclass
class MbrolaDatabase:
# TODO : init default values as specified in the database_init
freq: int # Sampling frequency of the database
mbr_period: int # Period of the MBR analysis
nb_diphone: int # Number of diphones in the database
size_mark: int # Size of the pitchmark part
pitch_marks: List[FrameType]
size_raw: int # Size of the wave part
raw_offset: int # Offset for raw samples in database
max_frame: int # Maximum number of frames encountered for a diphone in the dba
max_samples: int # Size of the diphone buffer= 0 means let me manage it myself
magic_header: Tuple[int, int] # Magic header of the database
version: str # version of the database
info: List[str]
silence_phone: str # silence symbol in the database
db_path: Path # name of database
if __name__ == "__main__":
args = argparser.parse_args()
if (MBROLA_VOICES_FOLDER / args.mbrola_db / args.mbrola_db).is_file():
db_path = MBROLA_VOICES_FOLDER / args.mbrola_db / args.mbrola_db
elif (MBROLA_VOICES_FOLDER / args.mbrola_db).is_file():
db_path = MBROLA_VOICES_FOLDER / args.mbrola_db
elif args.mbrola_db.is_file():
db_path = args.mbrola_db
else:
raise ValueError("Can't find database file")
mbr_db = MbrolaDatabase(db_path=db_path)
with open(db_path, "rb") as db_file:
# should read "mbrola"
mbr_db.magic_header = db_file.read(6).decode()
mbr_db.version = db_file.read(5).decode()
mbr_db.nb_diphone = int.from_bytes(db_file.read(2), byteorder="little")
Loading…
Cancel
Save