#
import re
import os
from re import findall
from xml.etree import ElementTree as ET
# Set the directories and files
rootDir = "E:\\Videos"
xmlpath = "E:\\Appz\\Vox\\payloads\\videos.xml"
txtfile = open("E:\\Appz\\Vox\\payloads\\videos_list.txt", "wb")
#function: get rid of unwanted characters
def cfix(zx):
global x
f2 = re.sub( '\s+', ' ', zx).strip()
f2 = f2.replace(" -", " ")
f2 = f2.replace("- ", " ")
f2 = f2.replace(" - ", " ")
f2 = f2.replace("-", " ")
f2 = f2.replace(":", " ")
f2 = f2.replace("_", " ")
f2 = f2.replace("5.1", "")
f2 = f2.replace(".", " ")
f2 = f2.replace("!", " ")
f2 = f2.replace("1080p", " ")
f2 = f2.replace("720p", " ")
f2 = f2.replace("x264", " ")
f2 = f2.replace("ac3", " ")
f2 = f2.replace("AC3", " ")
f2 = f2.replace("DTS", " ")
f2 = f2.replace("DVD", " ")
f2 = f2.replace("DvD", " ")
f2 = f2.replace("VOB", " ")
f2 = f2.replace("rip", " ")
f2 = f2.replace("aac", " ")
f2 = f2.replace("Rip", " ")
f2 = f2.replace("hd", " ")
f2 = f2.replace("HD", " ")
f2 = f2.replace("Hd", " ")
f2 = f2.replace("Hq", " ")
f2 = f2.replace("(", " ")
f2 = f2.replace(")", " ")
f2 = f2.replace("]", " ")
f2 = f2.replace("[", " ")
f2 = re.sub( '\s+', ' ', f2).strip()
x = f2
return x
#create the root </PayloadsRoot> <PayloadsRoot>
root_element = ET.Element("PayloadsRoot")
for dirName, subdirList, fileList in os.walk(rootDir):
for fname in fileList:
#create the first subelemet <payload> </payload>
pay_element = ET.SubElement(root_element, "payload")
#create the first child <value> </value>
child = ET.SubElement(pay_element, "value")
child.text = dirName +"\\" + fname
#create the second child <phrase> </phrase>
child = ET.Element("phrase")
#get the filename without the extension
fname = ('.').join(fname.split('.')[:-1])
#UnicodeEncodeError: 'ascii' codec can't encode character
fname.encode('ascii', 'ignore')
#get rid of unwanted characters
cfix(fname)
fileName = x
#print(fileName)
txtfile.write(str(fileName) + "\n")
child.text = fileName
#now append
pay_element.append(child)
txtfile.close()
def indent(elem, level=0):
i = "\n" + level*'\t'
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + '\t'
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
indent(root_element)
#View xml tree
#print ( ET.tostring(root_element) )
output_file = open(xmlpath, 'w' )
output_file.write( '<?xml version="1.0" encoding="utf-8"?>'+'\n' )
output_file.write( '<!--A VoxCommando Payload file-->' +'\n' )
output_file.write( ET.tostring(root_element) )
output_file.close()
I have done on the basis of this code, but do not understand how to read from peyloud.
Leave the path untouched and translated phrase.
I myself can finish the translation. I do not understand the command.
I understand that the translation will have to get out of the curve but
And how do you propose to use the 2 voice engine?
that I do not understand how for example to switch from 1 to another