├── .dockerignore
├── .github
└── workflows
│ ├── build_image.yml
│ └── docker_build_push.yml
├── .gitignore
├── .python-version
├── Dockerfile
├── LICENSE
├── README.md
├── build.sh
├── config
├── app.json
├── sentry.json
├── telegram.json
├── wit.json
└── yandex.json
├── data
└── .keep_folder
├── requirements.txt
├── run.sh
├── src
├── antiflood
│ ├── __init__.py
│ └── antiflood.py
├── audiotools
│ ├── __init__.py
│ └── speech.py
├── config
│ └── __init__.py
├── database
│ ├── __init__.py
│ └── db.py
├── functional
│ └── __init__.py
├── main.py
├── metaclass
│ ├── __init__.py
│ └── singleton.py
├── phototools
│ ├── __init__.py
│ ├── ocr.py
│ └── qr.py
├── resources
│ ├── __init__.py
│ └── loader.py
├── tests
│ └── test_db.py
├── transcriberbot
│ ├── blueprints
│ │ ├── __init__.py
│ │ ├── chat_handlers.py
│ │ ├── commands.py
│ │ ├── messages.py
│ │ ├── photos.py
│ │ └── voice.py
│ ├── bot.py
│ ├── filters
│ │ ├── __init__.py
│ │ └── filters.py
│ └── multiprocessing
│ │ ├── __init__.py
│ │ └── pools.py
└── translator
│ ├── __init__.py
│ └── translator.py
└── values
├── strings.xml
├── strings_de-DE.xml
├── strings_es-ES.xml
├── strings_it-IT.xml
└── strings_pt-BR.xml
/.dockerignore:
--------------------------------------------------------------------------------
1 | **/*.pyc
2 | **/__pycache__
3 | .git
4 | .pytest_cache
5 |
--------------------------------------------------------------------------------
/.github/workflows/build_image.yml:
--------------------------------------------------------------------------------
1 | name: DockerBuildAndPush
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - developement
8 | - ptb-async
9 |
10 | env:
11 | IMAGE_NAME: transcriberbot
12 |
13 | jobs:
14 | push:
15 | runs-on: ubuntu-latest
16 | if: github.event_name == 'push'
17 |
18 | steps:
19 | - uses: actions/checkout@v2
20 |
21 | - name: Login to ghcr registry
22 | run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
23 |
24 | - name: Build image
25 | run: docker build . --file Dockerfile --tag $IMAGE_NAME
26 |
27 | - name: Push image
28 | run: |
29 | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
30 | # Change all uppercase to lowercase
31 | IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
32 | # Strip git ref prefix from version
33 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
34 | # Strip "v" prefix from tag name
35 | [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
36 | # Use Docker `latest` tag convention
37 | [ "$VERSION" == "master" ] && VERSION=latest
38 | echo IMAGE_ID=$IMAGE_ID
39 | echo VERSION=$VERSION
40 | docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
41 | docker push $IMAGE_ID:$VERSION
--------------------------------------------------------------------------------
/.github/workflows/docker_build_push.yml:
--------------------------------------------------------------------------------
1 | name: DockerBuildAndPush
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - developement
8 |
9 | env:
10 | IMAGE_NAME: transcriberbot
11 |
12 | jobs:
13 | push:
14 | runs-on: ubuntu-latest
15 | if: github.event_name == 'push'
16 |
17 | steps:
18 | - uses: actions/checkout@v2
19 |
20 | - name: Login to ghcr registry
21 | run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
22 |
23 | - name: Build image
24 | run: docker build . --file Dockerfile --tag $IMAGE_NAME
25 |
26 | - name: Push image
27 | run: |
28 | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
29 | # Change all uppercase to lowercase
30 | IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
31 | # Strip git ref prefix from version
32 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
33 | # Strip "v" prefix from tag name
34 | [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
35 | # Use Docker `latest` tag convention
36 | [ "$VERSION" == "master" ] && VERSION=latest
37 | echo IMAGE_ID=$IMAGE_ID
38 | echo VERSION=$VERSION
39 | docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
40 | docker push $IMAGE_ID:$VERSION
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # TranscriberBot-specific ignores
2 | media/
3 |
4 | # Generic data-related ignores
5 | *.csv
6 | *.db
7 | *.sqlite
8 | *.sqlite3
9 | data/
10 | db.sqlite3
11 | db.sqlite3-journal
12 |
13 | # Generic Python-related ignores
14 | *$py.class
15 | *.cover
16 | *.egg
17 | *.egg-info/
18 | *.log
19 | *.manifest
20 | *.mo
21 | *.pot
22 | *.py,cover
23 | *.py[cod]
24 | *.pyc
25 | *.sage.py
26 | *.spec
27 | .Python
28 | .activate
29 | .cache
30 | .coverage
31 | .coverage.*
32 | .directory
33 | .dmypy.json
34 | .eggs/
35 | .env
36 | .hypothesis/
37 | .idea/*
38 | .installed.cfg
39 | .ipynb_checkpoints
40 | .ipynb_checkpoints/
41 | .mypy_cache/
42 | .nox/
43 | .pybuilder/
44 | .pyre/
45 | .pytest_cache/
46 | .pytype/
47 | .ropeproject
48 | .scrapy
49 | .spyderproject
50 | .spyproject
51 | .tox
52 | .tox/
53 | .venv
54 | .webassets-cache
55 | /site
56 | ENV/
57 | MANIFEST
58 | __pycache__/
59 | __pypackages__/
60 | build/
61 | build/*
62 | celerybeat-schedule
63 | celerybeat.pid
64 | cover/
65 | coverage.xml
66 | cython_debug/
67 | develop-eggs/
68 | dist/
69 | dist/*
70 | dmypy.json
71 | docs-build/
72 | docs/_build/
73 | docs/man/
74 | docs/reference/
75 | downloads/
76 | eggs/
77 | env.bak/
78 | env/
79 | htmlcov/
80 | instance/
81 | ipython_config.py
82 | lib/
83 | lib64/
84 | local_settings.py
85 | nosetests.xml
86 | parts/
87 | pip-delete-this-directory.txt
88 | pip-log.txt
89 | profile_default/
90 | reg_settings.py
91 | sdist/
92 | share/python-wheels/
93 | target/
94 | var/
95 | venv.bak/
96 | venv/
97 | wheels/
98 |
99 | # Other ignores
100 | *.so
101 | *.sw?
102 | *~
103 | .*.sw?
104 | .DS_Store
105 | .vscode/
106 |
--------------------------------------------------------------------------------
/.python-version:
--------------------------------------------------------------------------------
1 | transcriber-bot-wonda
2 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.12.0-slim
2 |
3 | # Set global configs
4 | WORKDIR /
5 | RUN export LC_ALL=C
6 | RUN export LC_CTYPE=C
7 | RUN export LC_NUMERIC=C
8 |
9 | # Install system dependencies
10 | RUN apt-get update
11 | RUN apt-get install --no-install-recommends -y \
12 | build-essential \
13 | ffmpeg \
14 | libleptonica-dev \
15 | libtesseract-dev \
16 | libzbar-dev \
17 | python3-dev \
18 | tesseract-ocr \
19 | && \
20 | apt-get clean
21 |
22 | # Install Python dependencies
23 | COPY requirements.txt .
24 | RUN pip install --no-cache-dir -U pip && \
25 | pip install --no-cache-dir -r requirements.txt
26 |
27 | # Copy code and define default command
28 | COPY src/ src/
29 |
30 | RUN useradd -m transcriber
31 | RUN chown -R transcriber src/
32 | RUN chown -R transcriber media/
33 |
34 | USER transcriber
35 |
36 | CMD [ "python", "src/main.py" ]
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Transcriber Bot
2 |
3 | [](https://t.me/Transcriber_bot)
4 | [](https://t.me/Transcriber_botNewsChannel)
5 |
6 | ## Quick Start
7 |
8 | 1. Create your own Telegram bot from @BotFather and take the bot token
9 |
10 | 2. Edit the file **config/telegram.json**
11 |
12 | ```json
13 | {
14 | "username": "BOT USERNAME",
15 | "token": "BOT TOKEN",
16 | "admins": [ "YOUR TELEGRAM ID" ]
17 | }
18 | ```
19 |
20 | 3. Create your own Wit token on [Wit website](https://wit.ai/docs/quickstart)
21 |
22 | 4. Edit the file **config/wit.json** (for example with italian token)
23 |
24 | ```json
25 | {
26 | "it-IT": "WIT TOKEN FOR Italian"
27 | }
28 | ```
29 |
30 | You can repeat the points 3 and 4 for support multiple languages.
31 |
32 | You can test if your token is working by running: `python src/audiotools/speech.py wit_api_key some_file.mp3 transcription.txt`
33 |
34 | 5. Create your own Yandex translate token on [Yandex website](https://tech.yandex.com/translate/)
35 |
36 | 6. Edit the file **config/yandex.json**
37 |
38 | ```json
39 | {
40 | "translate_key": "YOUR YANDEX TOKEN"
41 | }
42 | ```
43 |
44 | ## Running with Docker
45 |
46 | We provide prebuilt images on [ghcr.io](https://github.com/charslab/TranscriberBot/pkgs/container/transcriberbot).
47 | See **[run.sh](https://github.com/charslab/TranscriberBot/blob/developement/run.sh)** to start a docker container with the latest release.
48 |
49 | Altenratevely, you can build the image from the Dockerfile with **[build.sh](https://github.com/charslab/TranscriberBot/blob/developement/build.sh)**
50 |
51 | In **[run.sh](https://github.com/charslab/TranscriberBot/blob/developement/run.sh)**, the docker directories **config**, **data** and **values** are binding with the repository directory.
52 | If you want to edit the files in the configuration directories you can do this simply by stopping the container.
53 | As soon as you finish editing the files, just restart the container to make them active.
54 |
55 |
56 | ## Running with virtualenv
57 |
58 | Tested with: `python 3.12.0`
59 |
60 | First, install the required dependencies (Ubuntu):
61 |
62 | ```bash
63 | sudo apt install tesseract-ocr libtesseract-dev libleptonica-dev libpython3-dev libzbar-dev
64 | ```
65 | Create a virtual environment and install the required packages:
66 |
67 | ```bash
68 | python3 -m venv transcriber-bot
69 | source transcriber-bot/bin/activate
70 | pip install -r requirements.txt
71 | ```
72 | Run the bot:
73 |
74 | ```
75 | cd src
76 | python3 main.py
77 | ```
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | docker build --tag transcriberbot .
2 |
--------------------------------------------------------------------------------
/config/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "3.0.0",
3 | "database": "data/database.db",
4 | "media_path": "media",
5 | "languages" : {
6 | "arabic": "ar-EG",
7 | "catalan": "ca-ES",
8 | "chinese_hong_kong": "zh-HK",
9 | "chinese_traditional": "zh-TW",
10 | "chinese": "zh-CN",
11 | "danish": "da-DK",
12 | "dutch": "nl-NL",
13 | "english": "en-US",
14 | "english_uk": "en-GB",
15 | "english_us": "en-US",
16 | "finnish": "fi-FI",
17 | "french": "fr-FR",
18 | "german": "de-DE",
19 | "italian": "it-IT",
20 | "japanese": "ja-JP",
21 | "korean": "ko-KR",
22 | "norwegian": "nb-NO",
23 | "polish": "pl-PL",
24 | "portuguese_brazil": "pt-BR",
25 | "portuguese": "pt-PT",
26 | "russian": "ru-RU",
27 | "spanish": "es-ES",
28 | "swedish": "sv-SE",
29 | "turkish": "tr-TR"
30 | },
31 | "voice_max_threads": 30,
32 | "photos_max_threads": 10,
33 | "max_media_voice_file_size": 20971520,
34 |
35 | "audio_ext": [
36 | "3gpp",
37 | "m4a",
38 | "ogg",
39 | "ogx",
40 | "opus",
41 | "wav"
42 | ],
43 |
44 | "video_ext": [
45 | "avi",
46 | "mkv",
47 | "mp4",
48 | "ogv",
49 | "webm"
50 | ],
51 |
52 | "ocr": {
53 | "tesseract_path": "/usr/share/tesseract-ocr/5/tessdata/"
54 | },
55 |
56 | "antiflood": {
57 | "age_threshold": 10,
58 | "flood_ratio": 2,
59 | "max_flood_ratio": 6,
60 | "time_threshold_warning": 4,
61 | "time_threshold_flood": 5,
62 | "timeout": 10
63 | },
64 |
65 | "whisper": {
66 | "api_endpoint": "http://127.0.0.1:8000"
67 | },
68 |
69 | "logging": {
70 | "level": "APP"
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/config/sentry.json:
--------------------------------------------------------------------------------
1 | {
2 | "dsn": "xxx"
3 | }
--------------------------------------------------------------------------------
/config/telegram.json:
--------------------------------------------------------------------------------
1 | {
2 | "username": "xxxx",
3 | "token": "xxxxx",
4 | "admins": [
5 | "xxxx",
6 | "xxxx"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/config/wit.json:
--------------------------------------------------------------------------------
1 | {
2 | "ar-EG": "xxxxx",
3 | "ca-ES": "xxxxx",
4 | "da-DK": "xxxxx",
5 | "de-DE": "xxxxx",
6 | "en-GB": "xxxxx",
7 | "en-US": "xxxxx",
8 | "es-ES": "xxxxx",
9 | "fi-FI": "xxxxx",
10 | "fr-FR": "xxxxx",
11 | "it-IT": "xxxxx",
12 | "ja-JP": "xxxxx",
13 | "ko-KR": "xxxxx",
14 | "nb-NO": "xxxxx",
15 | "nl-NL": "xxxxx",
16 | "pl-PL": "xxxxx",
17 | "pt-BR": "xxxxx",
18 | "pt-PT": "xxxxx",
19 | "ru-RU": "xxxxx",
20 | "sv-SE": "xxxxx",
21 | "tr-TR": "xxxxx",
22 | "zh-CN": "xxxxx",
23 | "zh-HK": "xxxxx",
24 | "zh-TW": "xxxxx"
25 | }
--------------------------------------------------------------------------------
/config/yandex.json:
--------------------------------------------------------------------------------
1 | {
2 | "translate_key": "xxxx"
3 | }
--------------------------------------------------------------------------------
/data/.keep_folder:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/charslab/TranscriberBot/82d5e37ec7556923852718c58406812e34c407c2/data/.keep_folder
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | python-telegram-bot
2 | coloredlogs
3 | pillow
4 | watchdog
5 | tesserocr
6 | pydub
7 | zbarlight
8 | requests
9 | sentry-sdk
--------------------------------------------------------------------------------
/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | docker pull ghcr.io/charslab/transcriberbot:ptb-async
4 | docker run \
5 | -e LC_ALL=C \
6 | -d --restart unless-stopped \
7 | --name "transcriberbot-async" \
8 | -v "$(pwd)"/data:/data \
9 | -v "$(pwd)"/config:/config \
10 | -v "$(pwd)"/values:/values \
11 | -v "$(pwd)"/media:/media \
12 | --cpus=4.0 \
13 | --memory=3000m \
14 | -u "$(id -u):1337" \
15 | ghcr.io/charslab/transcriberbot:ptb-async
--------------------------------------------------------------------------------
/src/antiflood/__init__.py:
--------------------------------------------------------------------------------
1 | from antiflood.antiflood import on_chat_msg_received
2 | from antiflood.antiflood import register_flood_warning_callback
3 | from antiflood.antiflood import register_flood_started_callback
4 | from antiflood.antiflood import register_flood_ended_callback
5 | from antiflood.antiflood import init
6 |
--------------------------------------------------------------------------------
/src/antiflood/antiflood.py:
--------------------------------------------------------------------------------
1 | import config
2 | import time
3 | import logging
4 |
5 | logger = logging.getLogger(__name__)
6 |
7 | flood_ratio = 2 # messages/seconds
8 | max_flood_ratio = 10
9 | time_threshold_warning = 5 # ratio > flood_ratio for {time_threshold_warning} seconds
10 | time_threshold_flood = 10 # ratio > flood_ratio for {time_threshold_flood} seconds
11 | timeout = 4 # flood ends after ratio < flood_ratio for {timeout} seconds
12 |
13 | callback_flood_warning = None
14 | callback_flood_started = None
15 | callback_flood_ended = None
16 |
17 | LEVEL_NORMAL = 0
18 | LEVEL_WARNING = 1
19 | LEVEL_FLOOD = 2
20 | # chat_id -> (level, ratio, msg_num, duration, last_update)
21 | stats = {}
22 |
23 |
24 | def register_flood_warning_callback(callback):
25 | global callback_flood_warning
26 | callback_flood_warning = callback
27 |
28 |
29 | def register_flood_started_callback(callback):
30 | global callback_flood_started
31 | callback_flood_started = callback
32 |
33 |
34 | def register_flood_ended_callback(callback):
35 | global callback_flood_ended
36 | callback_flood_ended = callback
37 |
38 |
39 | def init():
40 | global flood_ratio, max_flood_ratio, time_threshold_warning, time_threshold_flood, timeout
41 | flood_ratio = config.get_config_prop("app")["antiflood"]["flood_ratio"]
42 | max_flood_ratio = config.get_config_prop("app")["antiflood"]["max_flood_ratio"]
43 | time_threshold_warning = config.get_config_prop("app")["antiflood"]["time_threshold_warning"]
44 | time_threshold_flood = config.get_config_prop("app")["antiflood"]["time_threshold_flood"]
45 | timeout = config.get_config_prop("app")["antiflood"]["timeout"]
46 |
47 | logger.info("Ratio: %d", flood_ratio)
48 | logger.info("Max flood ratio: %d", max_flood_ratio)
49 | logger.info("Thr warning: %d", time_threshold_warning)
50 | logger.info("Thr flood: %d", time_threshold_flood)
51 | logger.info("Timeout: %d", timeout)
52 |
53 |
54 | def on_chat_msg_received(chat_id):
55 | global flood_ratio, time_threshold_warning, time_threshold_flood, timeout
56 | global callback_flood_warning, callback_flood_started, callback_flood_ended
57 |
58 | curr_time = time.time()
59 |
60 | if chat_id not in stats:
61 | stats[chat_id] = [LEVEL_NORMAL, 1.0, 1, 0.0, curr_time]
62 |
63 | else:
64 | level, ratio, msg_num, duration, last_update = stats[chat_id]
65 | updated_duration = duration + curr_time - last_update
66 | msg_num += 1
67 | curr_ratio = msg_num / updated_duration
68 |
69 | if curr_ratio < flood_ratio and updated_duration > timeout:
70 | curr_ratio, updated_duration, msg_num = 0, 0, 0
71 | level = LEVEL_NORMAL
72 | if callback_flood_ended:
73 | callback_flood_ended(chat_id)
74 |
75 | elif updated_duration > 1 and curr_ratio > max_flood_ratio and level < LEVEL_FLOOD:
76 | level = LEVEL_FLOOD
77 | logger.warning("Flood ratio for chat %d is over the top", chat_id)
78 | if callback_flood_started:
79 | callback_flood_started(chat_id)
80 |
81 | elif curr_ratio > flood_ratio:
82 | if updated_duration >= time_threshold_flood and level < LEVEL_FLOOD:
83 | logger.warning("Flood detected for chat %d", chat_id)
84 | level = LEVEL_FLOOD
85 | if callback_flood_started:
86 | callback_flood_started(chat_id)
87 |
88 | elif updated_duration >= time_threshold_warning and level < LEVEL_WARNING:
89 | logger.info("Potential flood for chat %d", chat_id)
90 | level = LEVEL_WARNING
91 | if callback_flood_warning is not None:
92 | callback_flood_warning(chat_id)
93 |
94 | stats[chat_id] = (level, curr_ratio, msg_num, updated_duration, curr_time)
95 |
96 | logger.info("stats[{}]: {}".format(chat_id, stats[chat_id]))
97 |
--------------------------------------------------------------------------------
/src/audiotools/__init__.py:
--------------------------------------------------------------------------------
1 | from audiotools.speech import transcribe
2 |
--------------------------------------------------------------------------------
/src/audiotools/speech.py:
--------------------------------------------------------------------------------
1 | import io
2 | import logging
3 | import traceback
4 | import os
5 |
6 | import asyncio
7 | import requests
8 | from functools import partial
9 |
10 | import pydub
11 | from pydub import AudioSegment
12 | import config
13 | import textwrap
14 |
15 | logger = logging.getLogger("speech")
16 |
17 |
18 | class WitTranscriber:
19 | speech_url = "https://api.wit.ai/speech"
20 |
21 | def __init__(self, api_key):
22 | self.session = requests.Session()
23 | self.session.headers.update(
24 | {
25 | "Authorization": "Bearer " + api_key,
26 | "Accept": "application/vnd.wit.20180705+json",
27 | "Content-Type": "audio/raw;encoding=signed-integer;bits=16;rate=8000;endian=little",
28 | }
29 | )
30 |
31 | async def transcribe(self, chunk):
32 | text = None
33 | try:
34 | loop = asyncio.get_event_loop()
35 | response = await loop.run_in_executor(
36 | None, partial(self.session.post,
37 | url=self.speech_url,
38 | params={"verbose": True},
39 | data=io.BufferedReader(io.BytesIO(chunk.raw_data)))
40 | )
41 |
42 | logger.debug("Request response %s", response.text)
43 | data = response.json()
44 | if "_text" in data:
45 | text = data["_text"]
46 | elif "text" in data: # Changed in may 2020
47 | text = data["text"]
48 |
49 | except requests.exceptions.RequestException as e:
50 | logger.error("Could not transcribe chunk", exc_info=True)
51 |
52 | return text
53 |
54 | def close(self):
55 | self.session.close()
56 |
57 |
58 | def __generate_chunks(segment, length=20000 / 1001, split_on_silence=False, noise_threshold=-36):
59 | chunks = list()
60 | if split_on_silence is False:
61 | for i in range(0, len(segment), int(length * 1000)):
62 | chunks.append(segment[i:i + int(length * 1000)])
63 | else:
64 | while len(chunks) < 1:
65 | logger.debug('split_on_silence (threshold %d)', noise_threshold)
66 | chunks = pydub.silence.split_on_silence(segment, noise_threshold)
67 | noise_threshold += 4
68 |
69 | for i, chunk in enumerate(chunks):
70 | if len(chunk) > int(length * 1000):
71 | subchunks = __generate_chunks(chunk, length, split_on_silence, noise_threshold + 4)
72 | chunks = chunks[:i - 1] + subchunks + chunks[i + 1:]
73 |
74 | return chunks
75 |
76 |
77 | def __preprocess_audio(audio):
78 | return audio.set_sample_width(2).set_channels(1).set_frame_rate(8000)
79 |
80 |
81 | async def transcribe_wit(path, api_key):
82 | logger.info("Transcribing file %s", path)
83 | audio = AudioSegment.from_file(path)
84 |
85 | chunks = __generate_chunks(__preprocess_audio(audio))
86 | logger.debug("Got %d chunks", len(chunks))
87 |
88 | transcriber = WitTranscriber(api_key)
89 | for i, chunk in enumerate(chunks):
90 | logger.debug("Transcribing chunk %d", i)
91 | text = await transcriber.transcribe(chunk)
92 | logger.debug("Response received: %s", text)
93 |
94 | if text is not None:
95 | yield i, text, len(chunks)
96 | transcriber.close()
97 |
98 |
99 | async def transcribe_whisper(path):
100 | resp = requests.get(f"{config.get_config_prop('app')['whisper']['api_endpoint']}/transcribe?file_id={path}")
101 |
102 | # split the response into chunks of 4000 characters
103 | chunks = textwrap.wrap(resp.text, 4000)
104 | for idx, chunk in enumerate(chunks):
105 | yield idx, chunk, len(chunks)
106 |
107 |
108 | def transcribe(path, api_key, backend="wit"):
109 | if backend == "wit":
110 | logging.debug("Transcribing with wit")
111 | return transcribe_wit(path, api_key)
112 |
113 | elif backend == "whisper":
114 | logging.debug("Transcribing with whisper")
115 | return transcribe_whisper(os.path.basename(path))
116 |
117 | raise ValueError("Unknown backend: %s" % backend)
118 |
119 |
120 | if __name__ == "__main__":
121 | import argparse
122 | import sys
123 |
124 | parser = argparse.ArgumentParser()
125 | parser.add_argument("api_key")
126 | parser.add_argument("input_filename")
127 | parser.add_argument("output_filename")
128 | args = parser.parse_args()
129 |
130 | if args.output_filename == "-":
131 | output = sys.stdout
132 | else:
133 | output = open(args.output_filename, mode="w")
134 |
135 | result = transcribe(args.input_filename, args.api_key)
136 | for part, tot in result:
137 | output.write(part + "\n")
138 | output.flush()
139 |
140 | output.close()
141 |
--------------------------------------------------------------------------------
/src/config/__init__.py:
--------------------------------------------------------------------------------
1 | import os, glob
2 | import json
3 | import functional
4 | import logging
5 | import pprint
6 |
7 | APP_LOG = 25
8 |
9 | logger = logging.getLogger(__name__)
10 |
11 | __configs = {}
12 |
13 |
14 | def parse_file(file):
15 | logger.info("Loading config file %s", file)
16 |
17 | with open(file) as f:
18 | data = json.load(f)
19 | return data
20 |
21 |
22 | def init(config_folder):
23 | global __configs
24 | files = glob.glob(os.path.join(config_folder, "*.json"))
25 |
26 | keys = [x.replace(config_folder, "").replace(".json", "").replace("/", "") for x in files]
27 | configs = map(parse_file, files)
28 | __configs = dict(zip(keys, configs))
29 |
30 | base = os.path.join(os.path.dirname(__file__), "../../")
31 |
32 | if not os.path.isabs(__configs['app']['database']):
33 | __configs['app']['database'] = os.path.join(base, __configs['app']['database'])
34 |
35 | if not os.path.isabs(__configs['app']['media_path']):
36 | __configs['app']['media_path'] = os.path.join(base, __configs['app']['media_path'])
37 |
38 | if not os.path.isdir(__configs['app']['media_path']):
39 | os.mkdir(__configs['app']['media_path'])
40 |
41 |
42 | def get_config_prop(key):
43 | global __configs
44 | return __configs[key]
45 |
46 |
47 | def bot_token():
48 | return get_config_prop("telegram")["token"]
49 |
50 |
51 | def get_language_list():
52 | return get_config_prop("app")["languages"].keys()
53 |
54 |
55 | def get_audio_extensions():
56 | return get_config_prop("app").get("audio_ext", [])
57 |
58 |
59 | def get_video_extensions():
60 | return get_config_prop("app").get("video_ext", [])
61 |
62 |
63 | def get_document_extensions():
64 | audio_ext = get_audio_extensions()
65 | video_ext = get_video_extensions()
66 | return audio_ext + video_ext
67 |
68 |
69 | def get_bot_admins():
70 | return [int(id) for id in get_config_prop("telegram")["admins"]]
71 |
--------------------------------------------------------------------------------
/src/database/__init__.py:
--------------------------------------------------------------------------------
1 | from database.db import Database
2 | from database.db import TBDB
3 |
4 | """
5 | SCHEMA
6 |
7 | TABLE CHATS
8 | | chat_id (int) | lang (str) |
9 | voice_enabled (int) | photos_enabled (bool) |
10 | qr_enabled (bool) | active(bool) | ban (bool) |
11 |
12 | TABLE STATS
13 | | month_year (str) | audio_num (int) |
14 | min_tot_audio (int) | min_transcribed_audio (int) |
15 | num_pictures (int) |
16 |
17 | """
18 |
19 |
20 | def init_schema(database):
21 | with Database(database) as db:
22 | db.execute(
23 | "CREATE TABLE IF NOT EXISTS chats ("
24 | "chat_id INTEGER PRIMARY KEY, "
25 | "lang VARCHAR(5) NOT NULL, "
26 | "voice_enabled INTEGER,"
27 | "photos_enabled INTEGER,"
28 | "qr_enabled INTEGER,"
29 | "active INTEGER,"
30 | "ban INTEGER)"
31 | )
32 |
33 | db.execute(
34 | "CREATE TABLE IF NOT EXISTS stats ("
35 | "month_year INTEGER PRIMARY KEY,"
36 | "audio_num INTEGER, "
37 | "min_tot_audio INTEGER,"
38 | "min_transcribed_audio INTEGER,"
39 | "num_pictures INTEGER)"
40 | )
41 |
--------------------------------------------------------------------------------
/src/database/db.py:
--------------------------------------------------------------------------------
1 | import sqlite3
2 | import metaclass
3 | import logging
4 | import config
5 | import traceback
6 |
7 | logger = logging.getLogger(__name__)
8 |
9 |
10 | class Database():
11 | __instance = None
12 |
13 | def __init__(self, database):
14 | self.database = database
15 |
16 | def __connect(self):
17 | self.__connection = sqlite3.connect(self.database)
18 | self.__cursor = self.__connection.cursor()
19 |
20 | def __close(self):
21 | self.__connection.commit()
22 | self.__connection.close()
23 |
24 | def __enter__(self):
25 | logger.debug("__enter__")
26 | self.__connect()
27 | return self
28 |
29 | def assoc(self):
30 | self.__connection.row_factory = sqlite3.Row
31 | self.__cursor = self.__connection.cursor()
32 |
33 | def __exit__(self, exc_type, exc_value, exc_traceback):
34 | logger.debug("__exit__")
35 | self.__close()
36 |
37 | if exc_type:
38 | logger.error("exc_type: {}".format(exc_type))
39 | logger.error("exc_value: {}".format(exc_value))
40 | logger.error("exc_traceback: {}".format(exc_traceback))
41 | logger.error("Caught exception", exc_info=True)
42 |
43 | return True
44 |
45 | def execute(self, query, *args):
46 | res = self.__cursor.execute(query, *args)
47 | return self.__cursor
48 |
49 |
50 | class TBDB():
51 | @staticmethod
52 | def _get_db():
53 | return Database(config.get_config_prop("app")["database"])
54 |
55 | @staticmethod
56 | def create_default_chat_entry(chat_id, lang):
57 | with TBDB._get_db() as db:
58 | db.execute(
59 | "INSERT INTO chats(chat_id, lang, voice_enabled, photos_enabled, qr_enabled, active, ban) VALUES(?,?,?,?,?,?,?)",
60 | (chat_id, lang, 1, 0, 0, 1, 0)
61 | )
62 |
63 | @staticmethod
64 | def get_chat_entry(chat_id):
65 | with TBDB._get_db() as db:
66 | db.assoc()
67 | cursor = db.execute("SELECT * FROM chats WHERE chat_id='{0}'".format(chat_id))
68 | return cursor.fetchone()
69 |
70 | @staticmethod
71 | def get_chats():
72 | with TBDB._get_db() as db:
73 | db.assoc()
74 | cursor = db.execute("SELECT * FROM chats")
75 | return [dict(x) for x in cursor.fetchall()]
76 |
77 | @staticmethod
78 | def get_chat_lang(chat_id):
79 | chat_record = TBDB.get_chat_entry(chat_id)
80 | if not chat_record:
81 | logger.debug("Record for chat {} not found, creating one.".format(chat_id))
82 | TBDB.create_default_chat_entry(chat_id, "en-US")
83 | return "en-US"
84 |
85 | return chat_record["lang"]
86 |
87 | @staticmethod
88 | def set_chat_lang(chat_id, lang):
89 | with TBDB._get_db() as db:
90 | db.execute("UPDATE chats SET lang='{0}' WHERE chat_id='{1}'".format(lang, chat_id))
91 |
92 | @staticmethod
93 | def get_chat_voice_enabled(chat_id):
94 | try:
95 | with TBDB._get_db() as db:
96 | c = db.execute("SELECT voice_enabled FROM chats WHERE chat_id='{0}'".format(chat_id))
97 | return c.fetchone()[0]
98 | except TypeError as e:
99 | logger.error("Error getting voice_enabled for chat %d: %s", chat_id, e)
100 | raise e
101 |
102 | @staticmethod
103 | def set_chat_voice_enabled(chat_id, voice_enabled):
104 | with TBDB._get_db() as db:
105 | db.execute("UPDATE chats SET voice_enabled='{0}' WHERE chat_id='{1}'".format(voice_enabled, chat_id))
106 |
107 | @staticmethod
108 | def get_chat_photos_enabled(chat_id):
109 | with TBDB._get_db() as db:
110 | c = db.execute("SELECT photos_enabled FROM chats WHERE chat_id='{0}'".format(chat_id))
111 | return c.fetchone()[0]
112 |
113 | @staticmethod
114 | def set_chat_photos_enabled(chat_id, photos_enabled):
115 | with TBDB._get_db() as db:
116 | db.execute("UPDATE chats SET photos_enabled='{0}' WHERE chat_id='{1}'".format(photos_enabled, chat_id))
117 |
118 | @staticmethod
119 | def get_chat_qr_enabled(chat_id):
120 | with TBDB._get_db() as db:
121 | c = db.execute("SELECT qr_enabled FROM chats WHERE chat_id='{0}'".format(chat_id))
122 | return c.fetchone()[0]
123 |
124 | @staticmethod
125 | def set_chat_qr_enabled(chat_id, qr_enabled):
126 | with TBDB._get_db() as db:
127 | db.execute("UPDATE chats SET qr_enabled='{0}' WHERE chat_id='{1}'".format(qr_enabled, chat_id))
128 |
129 | @staticmethod
130 | def get_chat_active(chat_id):
131 | with TBDB._get_db() as db:
132 | c = db.execute("SELECT active FROM chats WHERE chat_id='{0}'".format(chat_id))
133 | return c.fetchone()[0]
134 |
135 | @staticmethod
136 | def set_chat_active(chat_id, active):
137 | with TBDB._get_db() as db:
138 | db.execute("UPDATE chats SET active='{0}' WHERE chat_id='{1}'".format(active, chat_id))
139 |
140 | @staticmethod
141 | def get_chat_ban(chat_id):
142 | with TBDB._get_db() as db:
143 | c = db.execute("SELECT ban FROM chats WHERE chat_id='{0}'".format(chat_id))
144 | return c.fetchone()[0]
145 |
146 | @staticmethod
147 | def set_chat_ban(chat_id, ban):
148 | with TBDB._get_db() as db:
149 | db.execute("UPDATE chats SET ban='{0}' WHERE chat_id='{1}'".format(ban, chat_id))
150 |
151 | @staticmethod
152 | def get_chats_num():
153 | with TBDB._get_db() as db:
154 | c = db.execute("SELECT count(*) FROM chats")
155 | return int(c.fetchone()[0])
156 |
157 | @staticmethod
158 | def get_active_chats_num():
159 | with TBDB._get_db() as db:
160 | c = db.execute("SELECT count(*) FROM chats where active=1")
161 | return int(c.fetchone()[0])
162 |
--------------------------------------------------------------------------------
/src/functional/__init__.py:
--------------------------------------------------------------------------------
1 | def apply_fn(list, fn):
2 | for item in list:
3 | fn(item)
4 |
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | import config
4 | import resources
5 | import database
6 | import antiflood
7 | import transcriberbot.bot
8 | import sentry_sdk
9 | from sentry_sdk.integrations.asyncio import AsyncioIntegration
10 |
11 | def main():
12 | config.init('../config')
13 |
14 | logging.addLevelName(config.APP_LOG, "APP")
15 |
16 | log_level = config.get_config_prop("app")["logging"]["level"]
17 | logging.basicConfig(
18 | format='%(asctime)s - %(name)s - %(levelname)s - %(filename)s [%(funcName)s:%(lineno)d] - %(message)s',
19 | level=log_level
20 | )
21 | logging.log(config.APP_LOG, "Setting log level to %s", log_level)
22 |
23 | resources.init("../values")
24 | antiflood.init()
25 | database.init_schema(config.get_config_prop("app")["database"])
26 |
27 | sentry_sdk.init(
28 | dsn=config.get_config_prop("sentry")["dsn"],
29 | # Add data like request headers and IP for users, if applicable;
30 | # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
31 | send_default_pii=True,
32 | # Set traces_sample_rate to 1.0 to capture 100%
33 | # of transactions for tracing.
34 | traces_sample_rate=1.0,
35 | # Set profiles_sample_rate to 1.0 to profile 100%
36 | # of sampled transactions.
37 | # We recommend adjusting this value in production.
38 | profiles_sample_rate=1.0,
39 | integrations=[
40 | AsyncioIntegration(),
41 | ],
42 | )
43 |
44 | sentry_sdk.profiler.start_profiler()
45 | transcriberbot.bot.run(config.bot_token())
46 |
47 |
48 | if __name__ == '__main__':
49 | main()
50 |
--------------------------------------------------------------------------------
/src/metaclass/__init__.py:
--------------------------------------------------------------------------------
1 | from metaclass.singleton import Singleton
2 |
--------------------------------------------------------------------------------
/src/metaclass/singleton.py:
--------------------------------------------------------------------------------
1 | class Singleton(type):
2 | _instances = {}
3 |
4 | def __call__(cls, *args, **kwargs):
5 | k = (cls, args)
6 | if k not in cls._instances:
7 | cls._instances[k] = super(Singleton, cls).__call__(*args, **kwargs)
8 | return cls._instances[k]
9 |
--------------------------------------------------------------------------------
/src/phototools/__init__.py:
--------------------------------------------------------------------------------
1 | from phototools.ocr import image_ocr
2 | from phototools.qr import read_qr
3 |
--------------------------------------------------------------------------------
/src/phototools/ocr.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | from tesserocr import PyTessBaseAPI
4 |
5 | import config
6 |
7 | logger = logging.getLogger(__name__)
8 |
9 |
10 | def image_ocr(path, lang):
11 | return image_ocr_tesserocr(path, lang)
12 |
13 |
14 | def image_ocr_docts(path, lang):
15 | from doctr.models import ocr_predictor
16 |
17 | predictor = ocr_predictor.create_predictor()
18 |
19 | # Perform OCR on the image
20 | predictor(path)
21 |
22 |
23 | def image_ocr_easyocr(path, lang):
24 | import easyocr
25 |
26 | logger.info("opening %s", path)
27 |
28 | reader = easyocr.Reader(['en'], gpu=False)
29 | result = reader.readtext(path)
30 | text = " ".join([x[1] for x in result])
31 |
32 | return text
33 |
34 |
35 | def image_ocr_tesserocr(path, lang):
36 | logger.info("opening %s", path)
37 |
38 | with PyTessBaseAPI(path=config.get_config_prop("app")["ocr"]["tesseract_path"]) as api:
39 | api.SetImageFile(path)
40 | text = api.GetUTF8Text().strip()
41 |
42 | return text
43 |
--------------------------------------------------------------------------------
/src/phototools/qr.py:
--------------------------------------------------------------------------------
1 | import zbarlight
2 | import logging
3 | from PIL import Image
4 |
5 | logger = logging.getLogger(__name__)
6 |
7 |
8 | def read_qr(path):
9 | logger.info("opening %s", path)
10 |
11 | with open(path, 'rb') as f:
12 | image = Image.open(f)
13 | image.load()
14 | qr = zbarlight.scan_codes('qrcode', image)
15 | if qr is not None:
16 | qr = qr[0].decode("utf-8")
17 |
18 | return qr
19 |
--------------------------------------------------------------------------------
/src/resources/__init__.py:
--------------------------------------------------------------------------------
1 | from resources.loader import init, get_string_resource, iso639_2_to_639_1
2 |
--------------------------------------------------------------------------------
/src/resources/loader.py:
--------------------------------------------------------------------------------
1 | import os, glob
2 | import xml.etree.ElementTree as ElementTree
3 | import functools
4 | import functional
5 | import logging
6 |
7 | from watchdog.observers import Observer
8 | from watchdog.events import FileSystemEventHandler
9 |
10 | logger = logging.getLogger(__name__)
11 | strings_r = {}
12 | __resources_directory = None
13 |
14 |
15 | class EventHandler(FileSystemEventHandler):
16 | @staticmethod
17 | def on_any_event(event):
18 | if event.event_type == "modified" or event.event_type == "created":
19 | logger.info("Reloading resource folder")
20 | load_config()
21 |
22 |
23 | def install_observer():
24 | handler = EventHandler()
25 | observer = Observer()
26 | observer.schedule(handler, __resources_directory)
27 | observer.start()
28 |
29 |
30 | def _load_xml_resouce(path):
31 | logger.info("Loading resource %s", path)
32 |
33 | e = ElementTree.parse(path).getroot()
34 | lang = e.get('lang')
35 | if lang not in strings_r:
36 | strings_r[lang] = {}
37 |
38 | replacements = (('{b}', ''), ('{/b}', ''),
39 | ('{i}', ''), ('{/i}', ''),
40 | ('{code}', ''), ('{/code}', '
'))
41 |
42 | for string in e.findall('string'):
43 | if string.text is None:
44 | continue
45 |
46 | value = functools.reduce(lambda s, kv: s.replace(*kv), replacements, string.text)
47 | value = value.strip()
48 | strings_r[lang][string.get('name')] = value
49 | logger.debug("Loaded string resource [%s] (%s): %s", string.get('name'), lang, value)
50 |
51 |
52 | def load_config():
53 | files = glob.glob(os.path.join(__resources_directory, "strings*.xml"))
54 | functional.apply_fn(files, _load_xml_resouce)
55 |
56 |
57 | def init(values_folder):
58 | global __resources_directory
59 | __resources_directory = values_folder
60 |
61 | load_config()
62 | install_observer()
63 |
64 |
65 | def iso639_2_to_639_1(lang):
66 | # Convert ISO 639-2 to 639-1 based on available translations (i.e it -> it-IT)
67 | return next(iter(list(filter(lambda s: s.startswith(lang), strings_r.keys()))), "en-US")
68 |
69 |
70 | def get_string_resource(id, lang=None):
71 | global strings_r
72 |
73 | if lang is not None and len(lang) < 5:
74 | lang = iso639_2_to_639_1(lang)
75 |
76 | rr = None
77 | if lang in strings_r and id in strings_r[lang]:
78 | rr = strings_r[lang][id]
79 | elif id in strings_r['default']:
80 | rr = strings_r['default'][id]
81 |
82 | return rr
83 |
--------------------------------------------------------------------------------
/src/tests/test_db.py:
--------------------------------------------------------------------------------
1 | import sys, os
2 |
3 | sys.path.append(os.path.abspath(os.path.join('.', 'src')))
4 |
5 | import config
6 | import database
7 | from database import TBDB
8 |
9 |
10 | def setup_function(function):
11 | config.init(os.path.abspath('config'))
12 | config.get_config_prop("app")["database"] = "tmp.db"
13 | database.init_schema(config.get_config_prop("app")["database"])
14 |
15 |
16 | def teardown_function(function):
17 | os.remove(config.get_config_prop("app")["database"])
18 |
19 |
20 | def test_db():
21 | id = 1234
22 |
23 | TBDB.create_default_chat_entry(id, 'en-US')
24 | assert TBDB.get_chat_lang(id) == 'en-US'
25 | assert TBDB.get_chat_active(id) == 1
26 |
27 | TBDB.set_chat_lang(id, 'lang')
28 | TBDB.set_chat_voice_enabled(id, 2)
29 | TBDB.set_chat_photos_enabled(id, 1)
30 | TBDB.set_chat_qr_enabled(id, 1)
31 | TBDB.set_chat_active(id, 0)
32 | TBDB.set_chat_ban(id, 1)
33 |
34 | assert TBDB.get_chat_lang(id) == 'lang'
35 | assert TBDB.get_chat_voice_enabled(id) == 2
36 | assert TBDB.get_chat_photos_enabled(id) == 1
37 | assert TBDB.get_chat_qr_enabled(id) == 1
38 | assert TBDB.get_chat_active(id) == 0
39 | assert TBDB.get_chat_ban(id) == 1
40 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | from . import commands, messages, voice, photos, chat_handlers
6 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/chat_handlers.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 16/02/25
4 | """
5 | import logging
6 | import config
7 |
8 | from telegram import Update, ChatMember
9 | from telegram.ext import ContextTypes
10 |
11 | from database import TBDB
12 |
13 |
14 | async def chat_member_update(update: Update, context: ContextTypes.DEFAULT_TYPE):
15 | chat_id = update.effective_chat.id
16 | logging.log(config.APP_LOG, "Chat {chat_id} member update: %s", update)
17 |
18 | left = update.my_chat_member.new_chat_member.status in (ChatMember.LEFT, ChatMember.BANNED)
19 |
20 | if left:
21 | TBDB.set_chat_active(chat_id, False)
22 | logging.log(config.APP_LOG, f"Chat {chat_id} deactivated")
23 | else:
24 | chat_record = TBDB.get_chat_entry(chat_id)
25 | if chat_record:
26 | TBDB.set_chat_active(chat_id, 1)
27 | logging.log(config.APP_LOG, f"Chat {chat_id} reactivated")
28 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/commands.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import logging
6 | import asyncio
7 | import traceback
8 | import datetime
9 |
10 | from telegram import Update
11 | from telegram.ext import ContextTypes
12 |
13 | import config
14 | import resources as R
15 | import translator
16 | from database import TBDB
17 |
18 |
19 | async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
20 | await welcome_message(update, context)
21 |
22 |
23 | async def lang(update: Update, context: ContextTypes.DEFAULT_TYPE):
24 | chat_lang = TBDB.get_chat_lang(update.effective_chat.id)
25 | await context.bot.send_message(
26 | update.effective_chat.id, R.get_string_resource("language_get", chat_lang).replace("{lang}", chat_lang)
27 | )
28 |
29 |
30 | async def rate(update: Update, context: ContextTypes.DEFAULT_TYPE):
31 | await context.bot.send_message(
32 | update.effective_chat.id,
33 | R.get_string_resource("message_rate", TBDB.get_chat_lang(update.effective_chat.id))
34 | )
35 |
36 |
37 | async def disable_voice(update: Update, context: ContextTypes.DEFAULT_TYPE):
38 | chat_id = update.effective_chat.id
39 | TBDB.set_chat_voice_enabled(chat_id, 0)
40 | await context.bot.send_message(
41 | chat_id, R.get_string_resource("voice_disabled", TBDB.get_chat_lang(chat_id))
42 | )
43 |
44 |
45 | async def enable_voice(update: Update, context: ContextTypes.DEFAULT_TYPE):
46 | chat_id = update.effective_chat.id
47 | TBDB.set_chat_voice_enabled(chat_id, 1)
48 | await context.bot.send_message(
49 | chat_id, R.get_string_resource("voice_enabled", TBDB.get_chat_lang(chat_id))
50 | )
51 |
52 |
53 | async def disable_photos(update: Update, context: ContextTypes.DEFAULT_TYPE):
54 | chat_id = update.effective_chat.id
55 | TBDB.set_chat_photos_enabled(chat_id, 0)
56 | await context.bot.send_message(
57 | chat_id, R.get_string_resource("photos_disabled", TBDB.get_chat_lang(chat_id))
58 | )
59 |
60 |
61 | async def enable_photos(update: Update, context: ContextTypes.DEFAULT_TYPE):
62 | chat_id = update.effective_chat.id
63 | TBDB.set_chat_photos_enabled(chat_id, 1)
64 | await context.bot.send_message(
65 | chat_id, R.get_string_resource("photos_enabled", TBDB.get_chat_lang(chat_id))
66 | )
67 |
68 |
69 | async def disable_qr(update: Update, context: ContextTypes.DEFAULT_TYPE):
70 | chat_id = update.effective_chat.id
71 | TBDB.set_chat_qr_enabled(chat_id, 0)
72 | await context.bot.send_message(
73 | chat_id, R.get_string_resource("qr_disabled", TBDB.get_chat_lang(chat_id))
74 | )
75 |
76 |
77 | async def enable_qr(update: Update, context: ContextTypes.DEFAULT_TYPE):
78 | chat_id = update.effective_chat.id
79 | TBDB.set_chat_qr_enabled(chat_id, 1)
80 | await context.bot.send_message(
81 | chat_id, R.get_string_resource("qr_enabled", TBDB.get_chat_lang(chat_id))
82 | )
83 |
84 |
85 | async def translate(update: Update, context: ContextTypes.DEFAULT_TYPE):
86 | chat_id = update.effective_chat.id
87 |
88 | lang = update.effective_message.text
89 | lang = lang.replace("/translate", "").strip()
90 | logging.debug("Language %s", lang)
91 |
92 | if not update.effective_message.reply_to_message:
93 | await context.bot.send_message(
94 | chat_id, R.get_string_resource("translate_reply_to_message", TBDB.get_chat_lang(chat_id))
95 | )
96 | return
97 |
98 | if not lang:
99 | await context.bot.send_message(
100 | chat_id, R.get_string_resource("translate_language_missing", TBDB.get_chat_lang(chat_id))
101 | )
102 | return
103 |
104 | if lang not in config.get_config_prop("app")["languages"]:
105 | await context.bot.send_message(
106 | chat_id, R.get_string_resource("translate_language_not_found", TBDB.get_chat_lang(chat_id)).format(lang)
107 | )
108 | return
109 |
110 | lang = config.get_config_prop("app")["languages"][lang].split('-')[0]
111 | translation = translator.translate(
112 | source=TBDB.get_chat_lang(chat_id),
113 | target=lang,
114 | text=update.effective_message.reply_to_message.text
115 | )
116 |
117 | await context.bot.send_message(
118 | chat_id, translation, reply_to_message_id=update.effective_message.reply_to_message.message_id
119 | )
120 |
121 |
122 | async def donate(update: Update, context: ContextTypes.DEFAULT_TYPE):
123 | chat_id = update.effective_chat.id
124 | await context.bot.send_message(
125 | chat_id, R.get_string_resource("message_donate", TBDB.get_chat_lang(chat_id)), parse_mode="html"
126 | )
127 |
128 |
129 | async def privacy(update: Update, context: ContextTypes.DEFAULT_TYPE):
130 | chat_id = update.effective_chat.id
131 | await context.bot.send_message(
132 | chat_id, R.get_string_resource("privacy_policy", TBDB.get_chat_lang(chat_id)), parse_mode="html"
133 | )
134 |
135 |
136 | async def welcome_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
137 | chat_record = TBDB.get_chat_entry(update.effective_chat.id)
138 |
139 | language = None
140 | if chat_record is not None:
141 | language = chat_record["lang"]
142 | elif update.effective_user.language_code is not None:
143 | # Channel posts do not have a language_code attribute
144 | logging.debug("Language_code: %s", update.effective_user.language_code)
145 | language = update.effective_user.language_code
146 |
147 | message = R.get_string_resource("message_welcome", language)
148 | message = message.replace("{languages}",
149 | "/" + "\n/".join(config.get_language_list())) # Format them to be a list of commands
150 |
151 | await context.bot.send_message(update.effective_chat.id, message, "html")
152 |
153 | if chat_record is None:
154 | if language is None:
155 | language = "en-US"
156 |
157 | if len(language) < 5:
158 | language = R.iso639_2_to_639_1(language)
159 |
160 | logging.debug(
161 | "No record found for chat {}, creating one with lang {}".format(update.effective_chat.id, language))
162 | TBDB.create_default_chat_entry(update.effective_chat.id, language)
163 |
164 |
165 | async def set_language(update: Update, context: ContextTypes.DEFAULT_TYPE, language):
166 | chat_id = update.effective_chat.id
167 | lang_ = config.get_config_prop("app")["languages"][language] # ISO 639-1 code for language
168 | TBDB.set_chat_lang(chat_id, lang_)
169 | message = R.get_string_resource("language_set", lang_).replace("{lang}", language)
170 | await context.bot.send_message(chat_id, message, parse_mode="html")
171 |
172 |
173 | async def users(update: Update, context: ContextTypes.DEFAULT_TYPE):
174 | chat_id = update.effective_chat.id
175 | tot_chats = TBDB.get_chats_num()
176 | active_chats = TBDB.get_active_chats_num()
177 | await context.bot.send_message(
178 | chat_id=chat_id, text='Total users: {}\nActive users: {}'.format(tot_chats, active_chats), parse_mode='html',
179 | )
180 |
181 |
182 | async def stats(update: Update, context: ContextTypes.DEFAULT_TYPE):
183 | num_audios = len(context.bot_data) - 1
184 | num_queues = context.bot_data.get('queue_len', 0)
185 |
186 | audio_queue = [f"{audio_id} duration {datetime.timedelta(seconds=v['duration'])} (received {v['time']}" for
187 | audio_id, v in
188 | context.bot_data.items() if
189 | audio_id != 'queue_len']
190 |
191 | await context.bot.send_message(
192 | update.effective_chat.id, f"Number of audios being currently processed: {num_audios}\n"
193 | f"Number of audios in queue: {num_queues}\n\n"
194 | f"{'\n'.join(audio_queue)}"
195 | )
196 |
197 |
198 | async def broadcast(update: Update, context: ContextTypes.DEFAULT_TYPE):
199 | chat_id = update.effective_chat.id
200 | text = " ".join(context.args)
201 |
202 | async def __post():
203 | chats = TBDB.get_chats()
204 | sent = 0
205 |
206 | for chat in chats:
207 | try:
208 | await context.bot.send_message(
209 | chat_id=chat['chat_id'],
210 | text=text,
211 | parse_mode='html',
212 | )
213 | sent += 1
214 | await asyncio.sleep(0.1)
215 | except Exception as e:
216 | logging.error(
217 | "Exception sending broadcast to %d: (%s)",
218 | chat['chat_id'], e, exc_info=True
219 | )
220 |
221 | await context.bot.send_message(
222 | chat_id=chat_id,
223 | text='Broadcast sent to {}/{} chats'.format(sent, len(chats)),
224 | )
225 |
226 | await __post()
227 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/messages.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import resources as R
6 |
7 | from telegram import Update
8 | from telegram.ext import ContextTypes
9 | from database import TBDB
10 |
11 |
12 | async def private_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
13 | await context.bot.send_message(
14 | update.effective_chat.id,
15 | R.get_string_resource("message_private", TBDB.get_chat_lang(update.effective_chat.id))
16 | )
17 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/photos.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import html
6 | import logging
7 | import os
8 | import traceback
9 |
10 | import telegram
11 | from telegram import Update
12 | from telegram.constants import ChatType
13 | from telegram.ext import ContextTypes
14 |
15 | import config
16 | import phototools
17 | import resources as R
18 | from database import TBDB
19 |
20 |
21 | async def photo(update: Update, context: ContextTypes.DEFAULT_TYPE):
22 | photo_enabled = update.effective_chat.type == ChatType.PRIVATE or TBDB.get_chat_photos_enabled(update.effective_chat.id)
23 | qr_enabled = update.effective_chat.type == ChatType.PRIVATE or TBDB.get_chat_qr_enabled(update.effective_chat.id)
24 |
25 | if not photo_enabled and not qr_enabled:
26 | return
27 |
28 | message = update.message or update.channel_post
29 | await process_media_photo(update, context, message.photo)
30 |
31 |
32 | async def process_media_photo(update: Update, context: ContextTypes.DEFAULT_TYPE, photo):
33 | chat_id = update.effective_chat.id
34 | message_id = update.effective_message.id
35 | lang = TBDB.get_chat_lang(chat_id)
36 |
37 | file_id = photo[-1].file_id
38 | file_path = os.path.join(config.get_config_prop("app")["media_path"], file_id)
39 | file: telegram.File = await context.bot.get_file(file_id)
40 | await file.download_to_drive(file_path)
41 |
42 | try:
43 | if update.effective_chat.type == ChatType.PRIVATE or TBDB.get_chat_qr_enabled(update.effective_chat.id):
44 | qr = phototools.read_qr(file_path)
45 | if qr is not None:
46 | qr = R.get_string_resource("qr_result", lang) + f"\n{qr}"
47 |
48 | await context.bot.send_message(
49 | chat_id=chat_id, text=qr, reply_to_message_id=message_id,
50 | parse_mode="html"
51 | )
52 | return
53 |
54 | if update.effective_chat.type == ChatType.PRIVATE or TBDB.get_chat_photos_enabled(update.effective_chat.id):
55 | text = phototools.image_ocr(file_path, lang)
56 | if text is not None:
57 | text = R.get_string_resource("ocr_result", lang) + "\n" + html.escape(text)
58 | await context.bot.send_message(
59 | text=text, chat_id=chat_id, reply_to_message_id=message_id,
60 | parse_mode="html",
61 | )
62 | return
63 |
64 |
65 | await context.bot.send_message(
66 | text=R.get_string_resource("photo_no_text", lang),
67 | chat_id=chat_id, reply_to_message_id=message_id,
68 | parse_mode="html",
69 | )
70 |
71 | except Exception as e:
72 | logging.error("Exception handling photo from %d", chat_id, exc_info=True)
73 |
74 | finally:
75 | os.remove(file_path)
76 |
--------------------------------------------------------------------------------
/src/transcriberbot/blueprints/voice.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import asyncio
6 | import logging
7 | import os
8 | import traceback
9 | import datetime
10 | from asyncio import CancelledError
11 |
12 | import telegram
13 | from telegram import Update, Voice, InlineKeyboardMarkup, InlineKeyboardButton, VideoNote, Document
14 | from telegram.constants import ChatType
15 | from telegram.ext import ContextTypes
16 |
17 | import audiotools
18 | import config
19 | import resources as R
20 | from database import TBDB
21 |
22 | logger = logging.getLogger(__name__)
23 |
24 |
25 | # TODO: check if cpu usage is too high, if so, use ProcessPoolExecutor
26 |
27 |
28 | async def voice_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
29 | if TBDB.get_chat_voice_enabled(update.effective_chat.id) == 0:
30 | return
31 |
32 | await run_voice_task(update, context, update.effective_message.voice, "voice")
33 |
34 |
35 | async def audio_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
36 | if TBDB.get_chat_voice_enabled(update.effective_chat.id) == 0:
37 | return
38 |
39 | await run_voice_task(update, context, update.effective_message.audio, "audio")
40 |
41 |
42 | async def video_note_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
43 | if TBDB.get_chat_voice_enabled(update.effective_chat.id) == 0:
44 | return
45 |
46 | await run_voice_task(update, context, update.effective_message.video_note, "video_note")
47 |
48 |
49 | async def document_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
50 | if TBDB.get_chat_voice_enabled(update.effective_chat.id) == 0:
51 | return
52 |
53 | await run_voice_task(update, context, update.effective_message.document, "document")
54 |
55 |
56 | async def stop_task(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
57 | task_id = int(update.callback_query.data)
58 | task: asyncio.Task = context.bot_data.get(task_id)["task"]
59 |
60 | if task is not None:
61 | task.cancel()
62 | context.bot_data.pop(task_id)
63 | else:
64 | logging.warning("Task not found")
65 |
66 |
67 | async def wait_for_task_queue(context: ContextTypes.DEFAULT_TYPE):
68 | # wait until there are less than N tasks in bot_data
69 | context.bot_data['queue_len'] = context.bot_data.get('queue_len', 0) + 1
70 |
71 | while len(context.bot_data) >= config.get_config_prop("app")["voice_max_threads"] + 1:
72 | logging.debug("Waiting for tasks to finish")
73 | await asyncio.sleep(1)
74 |
75 | context.bot_data['queue_len'] -= 1
76 | logging.debug("Task queue has available space")
77 |
78 |
79 | async def run_voice_task(update: Update, context: ContextTypes.DEFAULT_TYPE, media: Voice,
80 | name):
81 | await wait_for_task_queue(context)
82 |
83 | try:
84 | task = asyncio.create_task(process_media_voice(update, context, media, name))
85 | context.bot_data[update.effective_message.message_id] = {
86 | 'task': task,
87 | 'duration': media.duration,
88 | 'time': datetime.datetime.now(datetime.timezone.utc)
89 | }
90 | await asyncio.gather(task)
91 | finally:
92 | context.bot_data.pop(update.effective_message.message_id)
93 |
94 |
95 | async def process_media_voice(update: Update, context: ContextTypes.DEFAULT_TYPE, media: [Voice | VideoNote | Document],
96 | name: str) -> None:
97 | chat_id = update.effective_chat.id
98 | file_size = media.file_size
99 | max_size = config.get_config_prop("app").get("max_media_voice_file_size", 20 * 1024 * 1024)
100 |
101 | if file_size > max_size:
102 | error_message = R.get_string_resource("file_too_big", TBDB.get_chat_lang(chat_id)).format(
103 | max_size / (1024 * 1024)) + "\n"
104 | await context.bot.send_message(
105 | chat_id, error_message, parse_mode="html", reply_to_message_id=update.effective_message.message_id
106 | )
107 | return
108 |
109 | file_id = media.file_id
110 | file_path = os.path.join(config.get_config_prop("app")["media_path"], file_id)
111 | file: telegram.File = await context.bot.get_file(file_id)
112 | await file.download_to_drive(file_path)
113 |
114 | try:
115 | await transcribe_audio_file(update, context, file_path)
116 | except Exception:
117 | logger.error("Exception handling %s from %d", name, chat_id, exc_info=True)
118 | finally:
119 | os.remove(file_path)
120 |
121 |
122 | async def transcribe_audio_file(update: Update, context: ContextTypes.DEFAULT_TYPE, path: str):
123 | chat_id = update.effective_chat.id
124 | task_id = update.effective_message.message_id
125 | lang = TBDB.get_chat_lang(chat_id)
126 | is_group = update.effective_chat.type != ChatType.PRIVATE
127 |
128 | api_key = config.get_config_prop("wit").get(lang, None)
129 | if api_key is None:
130 | logger.error("Language not found in wit.json %s", lang)
131 | await context.bot.send_message(
132 | chat_id, R.get_string_resource("unknown_api_key", lang).format(language=lang), parse_mode="html",
133 | reply_to_message_id=update.effective_message.message_id
134 | )
135 | return
136 |
137 | logger.debug("Using key %s for lang %s", api_key, lang)
138 |
139 | message = await context.bot.send_message(
140 | chat_id, R.get_string_resource("transcribing", lang), parse_mode="html",
141 | reply_to_message_id=update.effective_message.message_id
142 | )
143 |
144 | logger.debug("Starting task %d", task_id)
145 | keyboard = InlineKeyboardMarkup(
146 | [[InlineKeyboardButton("Stop", callback_data=task_id)]]
147 | )
148 |
149 | text = ""
150 | if is_group:
151 | text = R.get_string_resource("transcription_text", lang) + "\n"
152 |
153 | try:
154 | async for idx, speech, n_chunks in audiotools.transcribe(path, api_key):
155 | logging.debug(f"Transcription idx={idx} n_chunks={n_chunks}, text={speech}")
156 | suffix = f" [{idx + 1}/{n_chunks}]" if idx < n_chunks - 1 else ""
157 | reply_markup = keyboard if idx < n_chunks - 1 else None
158 |
159 | if len(text + " " + speech) >= 4000:
160 | text = R.get_string_resource("transcription_continues", lang) + "\n"
161 | message = await context.bot.send_message(
162 | chat_id, f"{text} {speech} {suffix}",
163 | reply_to_message_id=message.message_id, parse_mode="html",
164 | reply_markup=reply_markup
165 | )
166 | else:
167 | message = await context.bot.edit_message_text(
168 | f"{text} {speech} {suffix}", chat_id=chat_id,
169 | message_id=message.message_id, parse_mode="html",
170 | reply_markup=reply_markup
171 | )
172 |
173 | text = f"{text} {speech}"
174 |
175 | # retry_num = 0
176 | # retry = True
177 | # while retry: # Retry loop
178 | # try:
179 | # if len(text + " " + speech) >= 4000:
180 | # text = R.get_string_resource("transcription_continues", lang) + "\n"
181 | # message = await context.bot.send_message(
182 | # chat_id, f"{text} {speech} {suffix}",
183 | # reply_to_message_id=message.message_id, parse_mode="html",
184 | # reply_markup=keyboard
185 | # )
186 | # else:
187 | # message = await context.bot.edit_message_text(
188 | # f"{text} {speech} {suffix}", chat_id=chat_id,
189 | # message_id=message.message_id, parse_mode="html",
190 | # reply_markup=keyboard
191 | # )
192 | #
193 | # text += " " + speech
194 | # retry = False
195 | #
196 | # except telegram.error.TimedOut as e:
197 | # print(e)
198 | # logger.error("Timeout error %s", traceback.format_exc())
199 | # retry_num += 1
200 | # if retry_num >= 3:
201 | # retry = False
202 | #
203 | # except telegram.error.RetryAfter as r:
204 | # logger.warning("Retrying after %d", r.retry_after)
205 | # await asyncio.sleep(r.retry_after)
206 | #
207 | # except telegram.error.TelegramError:
208 | # logger.error("Telegram error %s", traceback.format_exc())
209 | # retry = False
210 |
211 |
212 | except CancelledError:
213 | logging.debug("Task cancelled")
214 | await context.bot.edit_message_text(
215 | message.text + " " + R.get_string_resource("transcription_stopped", lang), chat_id=chat_id,
216 | message_id=message.message_id, parse_mode="html"
217 | )
218 | return
219 |
220 | except Exception as e:
221 | logger.error("Could not transcribe audio")
222 |
223 | await context.bot.edit_message_text(
224 | R.get_string_resource("transcription_failed", lang), chat_id=chat_id,
225 | message_id=message.message_id, parse_mode="html"
226 | )
227 |
228 | raise e
229 |
--------------------------------------------------------------------------------
/src/transcriberbot/bot.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | from telegram import Update
6 |
7 | import config
8 | import logging
9 |
10 | from telegram.ext import MessageHandler, ApplicationBuilder, CommandHandler, ContextTypes, CallbackQueryHandler, \
11 | ChatMemberHandler
12 | from functools import partial
13 | from transcriberbot.blueprints import commands, messages, voice, photos, chat_handlers
14 | from transcriberbot.blueprints.commands import set_language
15 |
16 | from telegram.ext.filters import VOICE, VIDEO_NOTE, AUDIO, PHOTO
17 | from transcriberbot.filters import chat_admin, FromPrivate, AllowedDocument, BotAdmin
18 |
19 |
20 | def run(bot_token: str):
21 | application = (ApplicationBuilder()
22 | .token(bot_token)
23 | .concurrent_updates(True)
24 | .build())
25 |
26 | logging.log(config.APP_LOG, "Installing handlers")
27 | application.add_handler(CallbackQueryHandler(voice.stop_task))
28 |
29 | application.add_handler(ChatMemberHandler(
30 | chat_handlers.chat_member_update,
31 | chat_member_types=ChatMemberHandler.MY_CHAT_MEMBER
32 | ))
33 |
34 | chat_admin_handlers = {
35 | 'start': commands.start,
36 | 'help': commands.start,
37 | 'lang': commands.lang,
38 | 'rate': commands.rate,
39 | 'disable_voice': commands.disable_voice,
40 | 'enable_voice': commands.enable_voice,
41 | 'disable_photos': commands.disable_photos,
42 | 'enable_photos': commands.enable_photos,
43 | 'disable_qr': commands.disable_qr,
44 | 'enable_qr': commands.enable_qr,
45 | 'translate': commands.translate,
46 | 'donate': commands.donate,
47 | 'privacy': commands.privacy
48 | }
49 |
50 | for command, callback in chat_admin_handlers.items():
51 | application.add_handler(CommandHandler(command, lambda u, c, cb=callback: chat_admin(u, c, cb)))
52 |
53 | logging.log(config.APP_LOG, "Installing language handlers..")
54 | for language in config.get_language_list():
55 | callback = partial(set_language, language=language)
56 | application.add_handler(
57 | CommandHandler(language, lambda u, c, cb=callback: chat_admin(u, c, cb))
58 | )
59 |
60 | logging.log(config.APP_LOG, "Installing admin controls")
61 | application.add_handler(CommandHandler("users", commands.users, filters=BotAdmin()))
62 | application.add_handler(CommandHandler("broadcast", commands.broadcast, filters=BotAdmin()))
63 | application.add_handler(CommandHandler("stats", commands.stats, filters=BotAdmin()))
64 |
65 | logging.log(config.APP_LOG, "Installing message handlers")
66 | application.add_handler(MessageHandler(VOICE, voice.voice_message))
67 | application.add_handler(MessageHandler(AUDIO, voice.audio_message))
68 | application.add_handler(MessageHandler(VIDEO_NOTE, voice.video_note_message))
69 | application.add_handler(MessageHandler(AllowedDocument(config.get_document_extensions()), voice.document_message))
70 |
71 | application.add_handler(MessageHandler(PHOTO, photos.photo))
72 |
73 | application.add_handler(MessageHandler(FromPrivate(), messages.private_message))
74 |
75 | logging.log(config.APP_LOG, "Starting bot..")
76 | application.run_polling(allowed_updates=Update.ALL_TYPES)
77 |
--------------------------------------------------------------------------------
/src/transcriberbot/filters/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | from .filters import *
6 |
--------------------------------------------------------------------------------
/src/transcriberbot/filters/filters.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import logging
6 | import asyncio
7 |
8 | from telegram.constants import ChatType
9 | from telegram.ext import ContextTypes
10 | from telegram.ext.filters import UpdateFilter
11 | from telegram import Update, ChatMember
12 |
13 | import config
14 |
15 |
16 | class AllowedDocument(UpdateFilter):
17 | """
18 | Checks if the message has document media with allowed extensions.
19 | """
20 |
21 | def __init__(self, allowed_exts) -> None:
22 | super().__init__()
23 | self.allowed_exts = allowed_exts
24 | if len(allowed_exts) == 0:
25 | logging.warning("No allowed extensions were provided. Documents will be disabled")
26 |
27 | def filter(self, update: Update) -> bool:
28 | if update.effective_message.animation:
29 | return False
30 |
31 | if update.effective_message.document:
32 | logging.debug("Received document %s", update.effective_message.document.file_id)
33 | filename = update.effective_message.document.file_name
34 | if '.' not in filename: # No extension
35 | return False
36 | ext = filename.split('.')[-1]
37 | return ext in self.allowed_exts
38 | return False
39 |
40 |
41 | class FromPrivate(UpdateFilter):
42 | """
43 | Checks if the message was sent in a private conversation.
44 | """
45 |
46 | def filter(self, update: Update) -> bool:
47 | return update.effective_chat.type == ChatType.PRIVATE
48 |
49 |
50 | class ChatAdmin(UpdateFilter):
51 | """
52 | Checks if the message was sent by a chat admin.
53 | """
54 |
55 | def filter(self, update: Update) -> bool:
56 | if update.effective_chat.type in (ChatType.PRIVATE, ChatType.CHANNEL):
57 | return True
58 |
59 | user = update.effective_user
60 | chat_admins: list[ChatMember] = asyncio.get_event_loop().run_until_complete(
61 | update.effective_chat.get_administrators())
62 |
63 | is_admin = list(filter(lambda admin: admin.user.id == user.id, chat_admins))
64 | is_admin = len(is_admin) > 0
65 |
66 | return is_admin
67 |
68 |
69 | async def chat_admin(update: Update, context: ContextTypes.DEFAULT_TYPE, callback):
70 |
71 | if update.effective_chat.type in (ChatType.PRIVATE, ChatType.CHANNEL):
72 | is_admin = True
73 | else:
74 | user = update.effective_user
75 |
76 | if user.id == 1087968824: # Anonymous admin
77 | is_admin = True
78 |
79 | else:
80 | chat_admins: list[ChatMember] = await update.effective_chat.get_administrators()
81 |
82 | is_admin = list(filter(lambda admin: admin.user.id == user.id, chat_admins))
83 | is_admin = len(is_admin) > 0
84 |
85 | if is_admin:
86 | return await callback(update, context)
87 |
88 |
89 | class BotAdmin(UpdateFilter):
90 | """
91 | Checks if the message was sent by the bot admin.
92 | """
93 |
94 | def filter(self, update: Update) -> bool:
95 | user = update.effective_user
96 | bot_admins = config.get_bot_admins()
97 |
98 | is_admin = list(filter(lambda admin_id: admin_id == user.id, bot_admins))
99 | is_admin = len(is_admin) > 0
100 |
101 | return is_admin
102 |
--------------------------------------------------------------------------------
/src/transcriberbot/multiprocessing/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | from .pools import voice_pool, init
6 |
--------------------------------------------------------------------------------
/src/transcriberbot/multiprocessing/pools.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: Carlo Alberto Barbano
3 | Date: 15/02/25
4 | """
5 | import logging
6 | import config
7 | from concurrent.futures import ThreadPoolExecutor
8 |
9 | voice_thread_pool, photos_thread_pool, misc_thread_pool = None, None, None
10 |
11 |
12 | def init():
13 | global voice_thread_pool
14 | global photos_thread_pool
15 | global misc_thread_pool
16 |
17 | voice_thread_pool = ThreadPoolExecutor(
18 | max_workers=config.get_config_prop("app")["voice_max_threads"]
19 | )
20 | photos_thread_pool = ThreadPoolExecutor(
21 | max_workers=config.get_config_prop("app")["photos_max_threads"]
22 | )
23 |
24 | misc_thread_pool = ThreadPoolExecutor(
25 | max_workers=2
26 | )
27 |
28 | print("POOLS INITIALIZED:", voice_thread_pool, photos_thread_pool, misc_thread_pool)
29 | logging.info("Thread pools initialized")
30 |
31 |
32 | def voice_pool():
33 | global voice_thread_pool
34 | return voice_thread_pool
35 |
--------------------------------------------------------------------------------
/src/translator/__init__.py:
--------------------------------------------------------------------------------
1 | from translator.translator import detect_language, translate
2 |
--------------------------------------------------------------------------------
/src/translator/translator.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import config
3 |
4 | yandex_detect_url = "https://translate.yandex.net/api/v1.5/tr.json/detect?key={}"
5 | yandex_translate_url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key={}"
6 |
7 |
8 | def detect_language(text):
9 | global yandex_detect_url
10 |
11 | r = requests.post(
12 | yandex_detect_url.format(config.get_config_prop("yandex")["translate_key"]),
13 | data={'text': text}
14 | )
15 | res = r.json()
16 |
17 | if 'lang' in res:
18 | return res['lang']
19 | else:
20 | return None
21 |
22 |
23 | def translate(source, target, text):
24 | return "Translation service currently unavailable."
25 | global yandex_translate_url
26 |
27 | autodetect = detect_language(text)
28 |
29 | if autodetect is not None:
30 | source = autodetect
31 | print("Autodetected language: {0}".format(autodetect))
32 |
33 | lang = source + "-" + target
34 | print(lang)
35 |
36 | r = requests.post(
37 | yandex_translate_url.format(config.get_config_prop("yandex")["translate_key"]),
38 | data={'lang': lang, 'text': text}
39 | )
40 |
41 | print(r)
42 | res = r.json()
43 | print(res)
44 | return str(res['text'][0]) + "\n\nPowered by Yandex.Translate http://translate.yandex.com"
45 |
--------------------------------------------------------------------------------
/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Language set to {lang}
5 | Current language: {lang}
6 |
7 |
8 | This bot transcribes audio and pictures into text. Add it to a group or forward audio messages and pictures to it.
9 | {b}Note{/b}: Within groups, the bot will respond to commands by {b}non-anonymous admins only{/b}
10 |
11 | Choose a language (for voice messages):
12 | {languages}
13 |
14 | /rate this bot or leave your feedback on {a href="https://telegram.me/storebot?start=transcriber_bot"}Store Bot{/a}
15 |
16 | If you have any trouble, or want to get in touch with the developers, contact @transcribersupport_bot
17 |
18 | If you like this bot, you can /donate. This will help us maintain the service and keep on improving it. Thank you!
19 |
20 |
21 | https://telegram.me/storebot?start=transcriber_bot
22 |
23 | You can make a donation for TranscriberBot on PayPal. This will really help us, thanks for your support!
24 | Money from donations will be used for paying the server and backend costs and let the devs make new features!
25 |
26 |
27 |
28 | You can also donate with Bitcoin, Ethereum or Litecoin
29 |
30 | BTC: {code}1DTrCfoNb9RLJnR5dfJvo9zwRjBZj8j1PY{/code}
31 |
32 | ETH: {code}0x0b784efc808527c75a8ef12a80622c41c28d45bd{/code}
33 |
34 | LTC: {code}LdsVPxqHR6PuKeMNvGYmMEkBRQ7M3AP3uY{/code}
35 |
36 |
37 | Send a voice message or a picture with some text
38 |
39 | Voice enabled
40 | Voice disabled
41 | Photos enabled
42 | Photos disabled
43 | QR enabled
44 | QR disabled
45 |
46 | Sorry, file is too big! (limit: {0}MB)
47 |
48 | Transcribing...
49 | Audio is very long ({0}s), this will take some time
50 | {b}Text:{/b}
51 | {b}[continues]:{/b}
52 | Could not transcribe audio
53 | {b}[Stopped]{/b}
54 |
55 | Recognizing...
56 | {b}Recognized Text:{/b}
57 | No text recognized
58 | {b}QR Code found:{/b}
59 | No QR code found
60 |
61 | {b}WARNING:{/b} Flood detected. Stop spamming please
62 |
63 | Unknown language: {language}
64 | Please specify a language to translate to, e.g. "/translate english"
65 | You must reply to a message in order to translate it
66 |
67 |
68 | We do not store any personal data or media content (such as audio or pictures).
69 | The only user data we store is the telegram chat id along with the chosen settings.
70 | Voice/audio messages are sent to {a href="https://wit.ai/terms"}wit.ai{/a} for transcription, and are immediately deleted after the transcription is completed.
71 | Pictures are immediately deleted from our server after OCR or QR recognition is perfomed (offline).
72 | We do NOT store ANY message content (text, multimedia or anything else).
73 |
74 |
75 | {b}ERROR:{/b} Oops, no wit.ai API key could be found for the language {language}. :(
76 |
77 |
78 |
--------------------------------------------------------------------------------
/values/strings_de-DE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {lang} als Sprache festgelegt
5 |
6 |
7 | Dieser Bot transkribiert Audio und Bilder in Text. Du kannst ihn einer Gruppe hinzufügen, oder Bilder und Sprachnachrichten an ihn weiterleiten.
8 | {b}Wichtig{/b}: Innerhalb von Gruppen antwortet dieser Bot nur auf Kommandos von {b}nicht-anonymen Admins{/b}
9 |
10 | Wähle eine Sprache (für Sprachnachrichten):
11 | {languages}
12 |
13 | Im {a href="https://telegram.me/storebot?start=transcriber_bot"}Store-Bot{/a} kannst du diesen Bot bewerten (/rate) oder Feedback hinterlassen!
14 |
15 | Wenn du Probleme hast oder mit den Entwicklern in Kontakt treten möchtest, nutze den Support-Bot @transcribersupport_bot!
16 |
17 | Wenn dir der Bot gefällt, kannst du den Entwicklern etwas spenden (/donate). Damit hilft du, den Dienst zu aufrecht zu erhalten und weiter zu verbessern. Vielen Dank!
18 |
19 |
20 | https://telegram.me/storebot?start=transcriber_bot
21 |
22 | Du kannst für TranscriberBot etwas über PayPal spenden. Das hilft uns wirklich sehr, vielen Dank für deine Unterstützung!
23 | Einnahmen aus Spenden nutzen wir für Server- und Backend-Kosten, außerdem können die Entwickler neue Funktionen einbauen!
24 |
25 |
26 |
27 | Du kannst auf in Bitcoin, Ethereum oder Litecoin spenden
28 |
29 | BTC: {code}1DTrCfoNb9RLJnR5dfJvo9zwRjBZj8j1PY{/code}
30 |
31 | ETH: {code}0x0b784efc808527c75a8ef12a80622c41c28d45bd{/code}
32 |
33 | LTC: {code}LdsVPxqHR6PuKeMNvGYmMEkBRQ7M3AP3uY{/code}
34 |
35 |
36 | Schicke eine Sprachnachricht oder ein Bild mit Text
37 |
38 | Sprache aktiviert
39 | Sprache deaktiviert
40 | Bilder aktiviert
41 | Bilder deaktiviert
42 | QR aktiviert
43 | QR deaktiviert
44 |
45 | Entschuldigung, diese Datei ist zu groß! (Limit: 20 MB)
46 |
47 | Wird transkribiert...
48 | Sprachnachricht ist sehr lang ({0} s), es dauert ein bisschen
49 | {b}Text:{/b}
50 | {b}[Fortsetzung]:{/b}
51 | Sprachnachricht konnte nicht transkribiert werden
52 | {b}[Ende]{/b}
53 |
54 | Wird erkannt...
55 | {b}Erkannter Text:{/b}
56 | Kein Text erkannt
57 | {b}QR-Code gefunden:{/b}
58 | Kein QR-Code gefunden
59 |
60 | {b}WARNUNG:{/b} Zu viele Nachrichten. Bitte höre auf, zu spammen
61 |
62 | Unbekannte Sprache: {language}
63 | Du musst auf eine Nachricht antworten, um die übersetzen zu können
64 |
65 |
66 | Wir speichern keinerlei persönliche Daten oder Dateien (z.B. Sprachnachrichten oder Bilder).
67 | Die einzigen Nutzerdaten, die wir erheben, ist die Telegram-Chat-ID zusammen mit deinen Einstellungen.
68 | Sprachnachrichten werden zur Transkription an {a href="https://wit.ai/terms"}wit.ai{/a} gesendet und direkt nach der Transkription gelöscht.
69 | Bilder werden direkt von unserem Server gelöscht, sobald die Text- oder QR-Erkennung abgeschlossen ist.
70 | Wir speichern keinerlei andere Nachrichteninhalte (Textnachrichten, Multimedia o.ä.)
71 |
72 |
73 | {b}FEHLER:{/b} Ups, für die Sprache {language} konnte kein wit.ai API-Schlüssel gefunden werden. :(
74 |
75 |
76 |
--------------------------------------------------------------------------------
/values/strings_es-ES.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Idioma establecido como Español
5 |
6 |
7 | Este bot transcribe audio e imágenes a texto.
8 | Añádeme a un grupo o reenvíame mensajes de audio o imagenes!
9 |
10 | Selecciona el idioma (para los mensajes de audio):
11 | {languages}
12 |
13 | Si tienes algún problema o quieres ponerte en contacto con los desarrolladores usa @transcribersupport_bot.
14 | Puedes donar usando /donate si te gusta el bot, ayudará a mantener el servidor y a mejorar el servicio!
15 |
16 | {b}Nota{/b}: en los grupos el bot sólo responderá a {b}comandos de administradores.{/b}
17 |
18 |
19 |
20 | Puedes hacer donaciones a TranscriberBot a través de PayPal.
21 | Las donaciones son de gran ayuda, gracias por el apoyo!
22 | El dinero de las donaciones se usará para cubrir los costes del servidor y apoyar a los desarrolladores.
23 |
24 |
25 |
26 | También puedes donar en Bitcoin, Ethereum o Litecoin
27 |
28 | BTC: {code}1DTrCfoNb9RLJnR5dfJvo9zwRjBZj8j1PY{/code}
29 |
30 | ETH: {code}0x0b784efc808527c75a8ef12a80622c41c28d45bd{/code}
31 |
32 | LTC: {code}LdsVPxqHR6PuKeMNvGYmMEkBRQ7M3AP3uY{/code}
33 |
34 |
35 |
36 | Mandame un mensaje de voz o una imagen con texto.
37 |
38 |
39 | Mensajes de voz activados
40 | Mensajes de voz desactivados
41 | Imágenes activadas
42 | Imágenes desactivadas
43 | QR activado
44 | QR desactivado
45 |
46 | ¡Lo siento, el archivo es demasiado grande! ({0}MB max)
47 |
48 | Transcribiendo...
49 | El audio es muy largo ({0}s), esto llevará un tiempo...
50 | {b}Texto:{/b}
51 | {b}[continúa]:{/b}
52 | No se ha podido transcribir el audio
53 | {b}[Interrumpido]{/b}
54 |
55 | Escaneando...
56 | {b}Texto reconocido:{/b}
57 | No se ha encontrado ningún texto
58 | {b}Restulado del QR:{/b}
59 | No se ha encontrado QR
60 |
61 | {b}Atención:{/b} flood detectado. Deja de espamear, por favor.
62 |
63 | Lenguaje desconocido: {language}
64 | Tienes que responder a un mensaje para traducirlo
65 |
66 |
67 | No guardamos ningún dato personal o de multimedia (como audio o mensajes)
68 | Los únicos datos de usuarios que guardamos son la id de chat y las preferencias del mismo.
69 | Los mensajes de audio se envían a (wit.ai https://wit.ai/terms) para la transcripción, y son inmediatamente borrados cuando la transcripción se ha completado.
70 | Las fotos se borran inmediatamente de nuestro servidor una vez se ha escandado en busca de texto o QR (offline).
71 | NO guardamos el contenido de NINGÚN mensaje (textp, multimedia o cualquier otra cosa)
72 |
73 |
74 | {b}ERROR:{/b} oops, no encontré la llave API Wit para la lengua {language}. :(
75 |
76 |
77 |
--------------------------------------------------------------------------------
/values/strings_it-IT.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lingua impostata in Italiano
5 |
6 |
7 | Questo bot trascrive messaggi vocali e immagini in testo.
8 | Aggiungimi ad un gruppo o inoltrami i messaggi vocali ricevuti.
9 |
10 | Scegli una lingua (per i messaggi vocali):
11 | {languages}
12 |
13 | Per qualsiasi problema, o per metterti in contatto con gli sviluppatori, usa @transcribersupport_bot.
14 | Puoi effettuare una donazione con il comando /donate, ci aiuterà a sostenere i costi del servizio e a migliorarlo.
15 |
16 | {b}Nota{/b}: nei gruppi, il bot risponderà solo ai comandi dati {b}dagli admin{/b}
17 |
18 |
19 |
20 | Puoi fare una donazione per TranscriberBot su PayPal.
21 | Le donazioni ci sono di grande aiuto, grazie!
22 | I ricavi verranno utilizzati per pagare il costo dei server e consentire lo sviluppo di nuove funzioni.
23 |
24 |
25 |
26 | Puoi anche effettuare una donazione in BTC, ETH o LTC
27 |
28 | BTC: {code}1DTrCfoNb9RLJnR5dfJvo9zwRjBZj8j1PY{/code}
29 |
30 | ETH: {code}0x0b784efc808527c75a8ef12a80622c41c28d45bd{/code}
31 |
32 | LTC: {code}LdsVPxqHR6PuKeMNvGYmMEkBRQ7M3AP3uY{/code}
33 |
34 |
35 |
36 | Mandami un messaggio vocale o un'immagine contenente del testo
37 |
38 |
39 | Voce abilitata
40 | Voce disabilitata
41 | Foto abilitate
42 | Foto disabilitate
43 | QR abilitato
44 | QR disabilitato
45 |
46 | Spiacente, il file è troppo grande! ({0}MB max)
47 |
48 | Trascrizione...
49 | L'audio è molto lungo ({0}s), ci vorrà un po'
50 | {b}Testo:{/b}
51 | {b}[continua]:{/b}
52 | Non sono riuscito a trascrivere l'audio
53 | {b}[Fermato]{/b}
54 |
55 | Riconoscimento...
56 | {b}Testo riconosciuto:{/b}
57 | Nessun testo riconosciuto
58 | {b}Codice QR rilevato:{/b}
59 | Nessun codice QR rilevato
60 |
61 | {b}ATTENZIONE:{/b} flood rilevato. Stop allo spam, perfavore
62 |
63 | Lingua sconosciuta: {language}
64 | Devi rispondere a un messaggio, per poterlo tradurre
65 |
66 |
67 | Non memorizziamo nessun dato personale o contenuto multimediale (come audio o immagini).
68 | Gli unici dati che conserviamo sono l'id della chat di telegram, insieme alle impostazioni scelte.
69 | I messaggi vocali/file audio sono inoltrati a wit.ai (https://wit.ai/terms) per la trascrizione, e vengono immediatamente cancellati al termine.
70 | Le immagini vengono rimosse dai nostri server dopo che l'OCR o il rilevamento di QR sono stati effettuati (offline).
71 |
72 | NON memorizziamo nessun CONTENUTO dei messaggi (testo, multimedia o altro).
73 |
74 |
75 | {b}ERRORE:{/b} ops, non ho trovato la chiave API Wit per la lingua {language}. :(
76 |
77 |
78 |
--------------------------------------------------------------------------------
/values/strings_pt-BR.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Linguagem definida para Português do Brasil
5 |
6 |
7 | Este bot transcreve áudio e imagens em texto.
8 | Adicione-me a um grupo ou encaminhe mensagens e imagens para mim!
9 |
10 | Escolha uma linguagem (para mensagens de voz):
11 | {languages}
12 |
13 | /rate avalie este bot ou deixe seu comentário aqui (https://telegram.me/storebot?start=transcriber_bot)
14 |
15 | Se estiver tendo problemas, ou quer entrar em contato com os desenvolvedores, contate @transcribersupport_bot
16 | Você pode /donate (doar) se gostar do bot. Isso nos ajudará a manter o serviço e continuar melhorando-o.
17 | {b}Observação{/b}: em grupos, o bot responderá {b}apenas comandos de administradores{/b}
18 |
19 |
20 | https://telegram.me/storebot?start=transcriber_bot
21 |
22 | Você pode doar para o TranscriberBot no Paypal. Nos ajudará muito, obrigado pelo seu apoio!
23 | Dinheiro das doações será usado para pagar o servidor, custos de desenvolvimento, e deixar os desenvolvedores fazerem novos recursos!
24 |
25 |
26 |
27 | Você também pode doar em BTC, ETH ou LTC
28 |
29 | BTC: {code}1DTrCfoNb9RLJnR5dfJvo9zwRjBZj8j1PY{/code}
30 |
31 | ETH: {code}0x0b784efc808527c75a8ef12a80622c41c28d45bd{/code}
32 |
33 | LTC: {code}LdsVPxqHR6PuKeMNvGYmMEkBRQ7M3AP3uY{/code}
34 |
35 |
36 | Envie-me uma mensagem de voz ou uma imagem com texto
37 |
38 | Voz ativada
39 | Voz desativada
40 | Imagens ativadas
41 | Imagens desativadas
42 | QR ativado
43 | QR desativado
44 |
45 | Desculpe, arquivo muito grande! (limite de {0}MB)
46 |
47 | Transcrevendo...
48 | Áudio muito longo ({0}s), isso demorará um pouco
49 | {b}Texto:{/b}
50 | {b}[continua]:{/b}
51 | Não pude transcrever o áudio
52 | {b}[Parado]{/b}
53 |
54 | Reconhecendo...
55 | {b}Texto reconhecido:{/b}
56 | Texto não reconhecido
57 | {b}Código QR encontrado:{/b}
58 | Código QR não encontrado
59 |
60 | {b}ATENÇÃO:{/b} flood detectado. Pare de fazer spam, por favor
61 |
62 | Linguagem desconhecida: {language}
63 | Você deve responder a uma mensagem para traduzí-la
64 |
65 |
66 | Nós não armazenamos nenhuma informação ou mídia pessoal (como audios ou imagens).
67 | Os únicos dados que armazenamos é o ID da conversa, juntamente com as configurações escolhidas.
68 | Mensagens de Voz/Áudio são enviadas para (wit.ai https://wit.ai/terms) para transcrição, e são imediatamente apagadas após a transcrição é finalizada.
69 | Imagens são imediatamente apagadas do nosso servidor após o reconhecimento de OCR ou QR é realizado (offline).
70 |
71 | Nós NÃO armazenamos NENHUM conteúdo de mensagens (texto, multimídia ou qualquer outra coisa).
72 |
73 |
74 | {b}ERRO:{/b} ops, não encontrei a chave de API Wit para a língua {language}. :(
75 |
76 |
77 |
--------------------------------------------------------------------------------