forked from mozilla/DeepSpeech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphabet_converte.py
51 lines (42 loc) · 1.76 KB
/
alphabet_converte.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
import os
########################################################################################
#
# A simple routine who use an alphabet string to assign a value to each character,
# and assign the n_character value.
#
#
# for use in DEEPSPEECH project
#
# Vincent FOUCAULT [email protected]
########################################################################################
# Mod v1.1 #
cwd = os.getcwd()
try :
with open(cwd+'data/alphabet.txt') as alphabet:
"read your alphabet file characters"
characters = alphabet.readlines()[1] #read lign 2
"transform to unicode"
characters = unicode(characters, 'utf8')
characters = characters.replace('\n','') # can be usefull, in case of line return on last alphabet letter
"split list"
characters = characters.split(',')
"assign number of characters in your personal alphabet"
characters_numbers = len(characters)
except :
print('\n\n-----------------------------------------------------------\n!!! Alphabet_converter must be started from Deepspeech dir\
\n-----------------------------------------------------------\n\n')
"Convert each letter to corresponding value"
def read(letter):
"replace the letter by an integer (ex: a,b,c,d c=3)"
if letter in characters:
letter = characters.index(letter)+1
else :
print("\n\n--------------------------------------------\n!!! the letter <"+letter+"> isn't in your alphabet !\
\nPlease change it content !\n--------------------------------------------\n\n")
return(letter)
"Return each value to corresponding letter"
def write(data):
data-=1
letter = characters[data]
return(letter)