Skip to content

Commit 5c5886f

Browse files
committed
Tools
1 parent 7bf3f66 commit 5c5886f

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,5 @@ pip-log.txt
218218
# Doxygen
219219
.DS_Store
220220
/.vs
221+
222+
out/

tools/CreateAudio.ipynb

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Audio Preparation\n",
8+
"We can prepare the needed audio files easily with the help of python. \n",
9+
"First we install gTTS which uses Google Translate for the generation of the audio files "
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"!pip3 install gTTS\n"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"## Generation of Audio Files\n",
26+
"\n",
27+
"The following logic generates the audio files based on an CSV file:"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 32,
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"out/audio/one.mp3\n",
40+
"out/audio/two.mp3\n",
41+
"out/audio/@menu1.mp3\n",
42+
"out/audio/@menu2.mp3\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"import csv\n",
48+
"import os\n",
49+
"import gtts\n",
50+
"\n",
51+
"directory = \"out/audio\"\n",
52+
"ext = \"mp3\"\n",
53+
"os.makedirs(directory,exist_ok=True)\n",
54+
"\n",
55+
"with open('audio.csv') as csvfile:\n",
56+
" audioreader = csv.DictReader(csvfile, delimiter=',')\n",
57+
" for row in audioreader:\n",
58+
" name = row['Name']\n",
59+
" text = row['Text']\n",
60+
" tts = gtts.gTTS(text)\n",
61+
" filename = directory + \"/\" + name + \".\" + ext\n",
62+
" tts.save(filename)\n",
63+
" print(filename)\n",
64+
"\n"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"metadata": {},
70+
"source": [
71+
"## Generating header files\n",
72+
"\n",
73+
"We can convert the audio files into C code:"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 31,
79+
"metadata": {},
80+
"outputs": [
81+
{
82+
"name": "stdout",
83+
"output_type": "stream",
84+
"text": [
85+
"xxd -i out/audio/one.mp3 out/h/one.h\n",
86+
"xxd -i out/audio/@menu1.mp3 out/h/@menu1.h\n",
87+
"xxd -i out/audio/@menu2.mp3 out/h/@menu2.h\n",
88+
"xxd -i out/audio/two.mp3 out/h/two.h\n"
89+
]
90+
}
91+
],
92+
"source": [
93+
"import os\n",
94+
"import sys\n",
95+
"from pathlib import Path\n",
96+
"\n",
97+
"h_directory = \"out/h\"\n",
98+
"os.makedirs(h_directory,exist_ok=True)\n",
99+
"\n",
100+
"for file in os.listdir(directory):\n",
101+
" filename = Path(file)\n",
102+
" filename_h = filename.with_suffix('.h')\n",
103+
" path_h = h_directory+\"/\"+str(filename_h)\n",
104+
" cmd = \"xxd -i \"+directory+\"/\"+file+\" \" + path_h\n",
105+
" print(cmd)\n",
106+
" os.system(cmd)\n",
107+
"\n",
108+
" # Read in the file\n",
109+
" with open(path_h, 'r') as file :\n",
110+
" filedata = file.read()\n",
111+
"\n",
112+
" # Replace the target string\n",
113+
" filedata = filedata.replace('unsigned char', '#pragma once\\nconst unsigned char')\n",
114+
"\n",
115+
" # Write the file out again\n",
116+
" with open(path_h, 'w') as file:\n",
117+
" file.write(filedata)\n",
118+
"\n"
119+
]
120+
}
121+
],
122+
"metadata": {
123+
"interpreter": {
124+
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
125+
},
126+
"kernelspec": {
127+
"display_name": "Python 3.9.10 64-bit",
128+
"language": "python",
129+
"name": "python3"
130+
},
131+
"language_info": {
132+
"codemirror_mode": {
133+
"name": "ipython",
134+
"version": 3
135+
},
136+
"file_extension": ".py",
137+
"mimetype": "text/x-python",
138+
"name": "python",
139+
"nbconvert_exporter": "python",
140+
"pygments_lexer": "ipython3",
141+
"version": "3.9.10"
142+
},
143+
"orig_nbformat": 4
144+
},
145+
"nbformat": 4,
146+
"nbformat_minor": 2
147+
}

tools/audio.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Name,Text
2+
one,one
3+
two,two
4+
@menu1,This is menu 1
5+
@menu2,This is menu 2

0 commit comments

Comments
 (0)