first commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 09:57:36 +08:00
commit a4c051946f
62 changed files with 21882 additions and 0 deletions

72
.drone.yml Normal file
View File

@@ -0,0 +1,72 @@
---
kind: pipeline
type: docker
name: learn-languages
platform:
os: linux
arch: amd64
volumes:
- name: debian-dist
host:
path: /home/debian/dist
steps:
- name: build
image: node:23-alpine
commands:
- npm ci
- npm run build
- name: package
image: node:23-alpine
commands:
- apk add zip
- mkdir -p .next/standalone/.next
- cp -r public .next/standalone
- cp -r .next/static .next/standalone/.next
- cd .next/standalone
- rm -f /dist/learn-languages.zip
- zip -r /dist/learn-languages.zip .
volumes:
- name: debian-dist
path: /dist
- name: deploy
image: appleboy/drone-ssh
environment:
ZHIPU_API_KEY:
from_secret: zhipu_api_key
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
password:
from_secret: ssh_password
port: 22
script:
- cd ~/
- rm -rf learn-languages
- mkdir learn-languages
- unzip -d learn-languages dist/learn-languages.zip
- cd learn-languages
- npm i
- |
if pm2 list | grep -q learn-languages; then
echo "进程 learn-languages 已在pm2中运行正在重启..."
ZHIPU_API_KEY=${ZHIPU_API_KEY} PORT=3030 pm2 restart "learn-languages"
else
echo "进程 learn-languages 未在pm2中运行正在启动..."
ZHIPU_API_KEY=${ZHIPU_API_KEY} PORT=3030 pm2 start "./server.js" --name "learn-languages"
fi
- pm2 save
- cd ~/
- rm -rf dist
- mkdir dist
debug: true
trigger:
branch:
- main

47
.gitignore vendored Normal file
View File

@@ -0,0 +1,47 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
deploy.sh
learn-languages.tar.gz
src/app/test
.env

674
LICENSE Normal file
View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

36
README.md Normal file
View File

@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

1
css.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
declare module '*.css';

25
eslint.config.mjs Normal file
View File

@@ -0,0 +1,25 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
{
ignores: [
"node_modules/**",
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
],
},
];
export default eslintConfig;

8
next.config.ts Normal file
View File

@@ -0,0 +1,8 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
output: "standalone"
};
export default nextConfig;

14958
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

31
package.json Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "learn-languages",
"version": "0.1.0",
"private": true,
"license": "GPL-3.0-only",
"scripts": {
"dev": "next dev --turbopack",
"build": "next build --turbopack",
"start": "next start",
"lint": "eslint"
},
"dependencies": {
"clsx": "^2.1.1",
"edge-tts-universal": "^1.3.2",
"next": "15.5.3",
"react": "19.1.0",
"react-dom": "19.1.0",
"zod": "^3.25.76"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.5.3",
"tailwindcss": "^4",
"typescript": "^5"
}
}

5
postcss.config.mjs Normal file
View File

@@ -0,0 +1,5 @@
const config = {
plugins: ["@tailwindcss/postcss"],
};
export default config;

View File

@@ -0,0 +1,132 @@
[
{
"letter": "a",
"letter_name_ipa": "[eɪ]",
"letter_sound_ipa": "[æ], [eɪ], [ɑː], [ə]"
},
{
"letter": "b",
"letter_name_ipa": "[biː]",
"letter_sound_ipa": "[b]"
},
{
"letter": "c",
"letter_name_ipa": "[siː]",
"letter_sound_ipa": "[k], [s]"
},
{
"letter": "d",
"letter_name_ipa": "[diː]",
"letter_sound_ipa": "[d]"
},
{
"letter": "e",
"letter_name_ipa": "[iː]",
"letter_sound_ipa": "[ɛ], [iː], [ə]"
},
{
"letter": "f",
"letter_name_ipa": "[ɛf]",
"letter_sound_ipa": "[f]"
},
{
"letter": "g",
"letter_name_ipa": "[dʒiː]",
"letter_sound_ipa": "[ɡ], [dʒ]"
},
{
"letter": "h",
"letter_name_ipa": "[eɪtʃ]",
"letter_sound_ipa": "[h]"
},
{
"letter": "i",
"letter_name_ipa": "[aɪ]",
"letter_sound_ipa": "[ɪ], [aɪ]"
},
{
"letter": "j",
"letter_name_ipa": "[dʒeɪ]",
"letter_sound_ipa": "[dʒ]"
},
{
"letter": "k",
"letter_name_ipa": "[keɪ]",
"letter_sound_ipa": "[k]"
},
{
"letter": "l",
"letter_name_ipa": "[ɛl]",
"letter_sound_ipa": "[l]"
},
{
"letter": "m",
"letter_name_ipa": "[ɛm]",
"letter_sound_ipa": "[m]"
},
{
"letter": "n",
"letter_name_ipa": "[ɛn]",
"letter_sound_ipa": "[n]"
},
{
"letter": "o",
"letter_name_ipa": "[oʊ]",
"letter_sound_ipa": "[ɒ], [oʊ], [ʌ]"
},
{
"letter": "p",
"letter_name_ipa": "[piː]",
"letter_sound_ipa": "[p]"
},
{
"letter": "q",
"letter_name_ipa": "[kjuː]",
"letter_sound_ipa": "[k]"
},
{
"letter": "r",
"letter_name_ipa": "[ɑːr]",
"letter_sound_ipa": "[r]"
},
{
"letter": "s",
"letter_name_ipa": "[ɛs]",
"letter_sound_ipa": "[s], [z]"
},
{
"letter": "t",
"letter_name_ipa": "[tiː]",
"letter_sound_ipa": "[t]"
},
{
"letter": "u",
"letter_name_ipa": "[juː]",
"letter_sound_ipa": "[ʌ], [juː], [ʊ]"
},
{
"letter": "v",
"letter_name_ipa": "[viː]",
"letter_sound_ipa": "[v]"
},
{
"letter": "w",
"letter_name_ipa": "[ˈdʌbəl.juː]",
"letter_sound_ipa": "[w]"
},
{
"letter": "x",
"letter_name_ipa": "[ɛks]",
"letter_sound_ipa": "[ks], [ɡz]"
},
{
"letter": "y",
"letter_name_ipa": "[waɪ]",
"letter_sound_ipa": "[j], [aɪ], [ɪ]"
},
{
"letter": "z",
"letter_name_ipa": "[zɛd] or [ziː]",
"letter_sound_ipa": "[z]"
}
]

View File

@@ -0,0 +1,142 @@
[
{
"letter": "a",
"letter_name_ipa": "[a]",
"letter_sound_ipa": "[a]"
},
{
"letter": "b",
"letter_name_ipa": "[bo]",
"letter_sound_ipa": "[b]"
},
{
"letter": "c",
"letter_name_ipa": "[t͡so]",
"letter_sound_ipa": "[t͡s]"
},
{
"letter": "ĉ",
"letter_name_ipa": "[t͡ʃo]",
"letter_sound_ipa": "[t͡ʃ]"
},
{
"letter": "d",
"letter_name_ipa": "[do]",
"letter_sound_ipa": "[d]"
},
{
"letter": "e",
"letter_name_ipa": "[e]",
"letter_sound_ipa": "[e]"
},
{
"letter": "f",
"letter_name_ipa": "[fo]",
"letter_sound_ipa": "[f]"
},
{
"letter": "g",
"letter_name_ipa": "[ɡo]",
"letter_sound_ipa": "[ɡ]"
},
{
"letter": "ĝ",
"letter_name_ipa": "[d͡ʒo]",
"letter_sound_ipa": "[d͡ʒ]"
},
{
"letter": "h",
"letter_name_ipa": "[ho]",
"letter_sound_ipa": "[h]"
},
{
"letter": "ĥ",
"letter_name_ipa": "[xo]",
"letter_sound_ipa": "[x]"
},
{
"letter": "i",
"letter_name_ipa": "[i]",
"letter_sound_ipa": "[i]"
},
{
"letter": "j",
"letter_name_ipa": "[jo]",
"letter_sound_ipa": "[j]"
},
{
"letter": "ĵ",
"letter_name_ipa": "[ʒo]",
"letter_sound_ipa": "[ʒ]"
},
{
"letter": "k",
"letter_name_ipa": "[ko]",
"letter_sound_ipa": "[k]"
},
{
"letter": "l",
"letter_name_ipa": "[lo]",
"letter_sound_ipa": "[l]"
},
{
"letter": "m",
"letter_name_ipa": "[mo]",
"letter_sound_ipa": "[m]"
},
{
"letter": "n",
"letter_name_ipa": "[no]",
"letter_sound_ipa": "[n]"
},
{
"letter": "o",
"letter_name_ipa": "[o]",
"letter_sound_ipa": "[o]"
},
{
"letter": "p",
"letter_name_ipa": "[po]",
"letter_sound_ipa": "[p]"
},
{
"letter": "r",
"letter_name_ipa": "[ro]",
"letter_sound_ipa": "[r]"
},
{
"letter": "s",
"letter_name_ipa": "[so]",
"letter_sound_ipa": "[s]"
},
{
"letter": "ŝ",
"letter_name_ipa": "[ʃo]",
"letter_sound_ipa": "[ʃ]"
},
{
"letter": "t",
"letter_name_ipa": "[to]",
"letter_sound_ipa": "[t]"
},
{
"letter": "u",
"letter_name_ipa": "[u]",
"letter_sound_ipa": "[u]"
},
{
"letter": "ŭ",
"letter_name_ipa": "[u̯o]",
"letter_sound_ipa": "[u̯]"
},
{
"letter": "v",
"letter_name_ipa": "[vo]",
"letter_sound_ipa": "[v]"
},
{
"letter": "z",
"letter_name_ipa": "[zo]",
"letter_sound_ipa": "[z]"
}
]

View File

@@ -0,0 +1,554 @@
[
{
"letter": "あ",
"letter_name_ipa": "[a]",
"letter_sound_ipa": "[a]",
"roman_letter": "a"
},
{
"letter": "ア",
"letter_name_ipa": "[a]",
"letter_sound_ipa": "[a]",
"roman_letter": "a"
},
{
"letter": "い",
"letter_name_ipa": "[i]",
"letter_sound_ipa": "[i]",
"roman_letter": "i"
},
{
"letter": "イ",
"letter_name_ipa": "[i]",
"letter_sound_ipa": "[i]",
"roman_letter": "i"
},
{
"letter": "う",
"letter_name_ipa": "[ɯ]",
"letter_sound_ipa": "[ɯ]",
"roman_letter": "u"
},
{
"letter": "ウ",
"letter_name_ipa": "[ɯ]",
"letter_sound_ipa": "[ɯ]",
"roman_letter": "u"
},
{
"letter": "え",
"letter_name_ipa": "[e]",
"letter_sound_ipa": "[e]",
"roman_letter": "e"
},
{
"letter": "エ",
"letter_name_ipa": "[e]",
"letter_sound_ipa": "[e]",
"roman_letter": "e"
},
{
"letter": "お",
"letter_name_ipa": "[o]",
"letter_sound_ipa": "[o]",
"roman_letter": "o"
},
{
"letter": "オ",
"letter_name_ipa": "[o]",
"letter_sound_ipa": "[o]",
"roman_letter": "o"
},
{
"letter": "か",
"letter_name_ipa": "[ka]",
"letter_sound_ipa": "[ka]",
"roman_letter": "ka"
},
{
"letter": "カ",
"letter_name_ipa": "[ka]",
"letter_sound_ipa": "[ka]",
"roman_letter": "ka"
},
{
"letter": "き",
"letter_name_ipa": "[ki]",
"letter_sound_ipa": "[ki]",
"roman_letter": "ki"
},
{
"letter": "キ",
"letter_name_ipa": "[ki]",
"letter_sound_ipa": "[ki]",
"roman_letter": "ki"
},
{
"letter": "く",
"letter_name_ipa": "[kɯ]",
"letter_sound_ipa": "[kɯ]",
"roman_letter": "ku"
},
{
"letter": "ク",
"letter_name_ipa": "[kɯ]",
"letter_sound_ipa": "[kɯ]",
"roman_letter": "ku"
},
{
"letter": "け",
"letter_name_ipa": "[ke]",
"letter_sound_ipa": "[ke]",
"roman_letter": "ke"
},
{
"letter": "ケ",
"letter_name_ipa": "[ke]",
"letter_sound_ipa": "[ke]",
"roman_letter": "ke"
},
{
"letter": "こ",
"letter_name_ipa": "[ko]",
"letter_sound_ipa": "[ko]",
"roman_letter": "ko"
},
{
"letter": "コ",
"letter_name_ipa": "[ko]",
"letter_sound_ipa": "[ko]",
"roman_letter": "ko"
},
{
"letter": "さ",
"letter_name_ipa": "[sa]",
"letter_sound_ipa": "[sa]",
"roman_letter": "sa"
},
{
"letter": "サ",
"letter_name_ipa": "[sa]",
"letter_sound_ipa": "[sa]",
"roman_letter": "sa"
},
{
"letter": "し",
"letter_name_ipa": "[ɕi]",
"letter_sound_ipa": "[ɕi]",
"roman_letter": "shi"
},
{
"letter": "シ",
"letter_name_ipa": "[ɕi]",
"letter_sound_ipa": "[ɕi]",
"roman_letter": "shi"
},
{
"letter": "す",
"letter_name_ipa": "[sɯ]",
"letter_sound_ipa": "[sɯ]",
"roman_letter": "su"
},
{
"letter": "ス",
"letter_name_ipa": "[sɯ]",
"letter_sound_ipa": "[sɯ]",
"roman_letter": "su"
},
{
"letter": "せ",
"letter_name_ipa": "[se]",
"letter_sound_ipa": "[se]",
"roman_letter": "se"
},
{
"letter": "セ",
"letter_name_ipa": "[se]",
"letter_sound_ipa": "[se]",
"roman_letter": "se"
},
{
"letter": "そ",
"letter_name_ipa": "[so]",
"letter_sound_ipa": "[so]",
"roman_letter": "so"
},
{
"letter": "ソ",
"letter_name_ipa": "[so]",
"letter_sound_ipa": "[so]",
"roman_letter": "so"
},
{
"letter": "た",
"letter_name_ipa": "[ta]",
"letter_sound_ipa": "[ta]",
"roman_letter": "ta"
},
{
"letter": "タ",
"letter_name_ipa": "[ta]",
"letter_sound_ipa": "[ta]",
"roman_letter": "ta"
},
{
"letter": "ち",
"letter_name_ipa": "[tɕi]",
"letter_sound_ipa": "[tɕi]",
"roman_letter": "chi"
},
{
"letter": "チ",
"letter_name_ipa": "[tɕi]",
"letter_sound_ipa": "[tɕi]",
"roman_letter": "chi"
},
{
"letter": "つ",
"letter_name_ipa": "[t͡sɯ]",
"letter_sound_ipa": "[t͡sɯ]",
"roman_letter": "tsu"
},
{
"letter": "ツ",
"letter_name_ipa": "[t͡sɯ]",
"letter_sound_ipa": "[t͡sɯ]",
"roman_letter": "tsu"
},
{
"letter": "て",
"letter_name_ipa": "[te]",
"letter_sound_ipa": "[te]",
"roman_letter": "te"
},
{
"letter": "テ",
"letter_name_ipa": "[te]",
"letter_sound_ipa": "[te]",
"roman_letter": "te"
},
{
"letter": "と",
"letter_name_ipa": "[to]",
"letter_sound_ipa": "[to]",
"roman_letter": "to"
},
{
"letter": "ト",
"letter_name_ipa": "[to]",
"letter_sound_ipa": "[to]",
"roman_letter": "to"
},
{
"letter": "な",
"letter_name_ipa": "[na]",
"letter_sound_ipa": "[na]",
"roman_letter": "na"
},
{
"letter": "ナ",
"letter_name_ipa": "[na]",
"letter_sound_ipa": "[na]",
"roman_letter": "na"
},
{
"letter": "に",
"letter_name_ipa": "[ni]",
"letter_sound_ipa": "[ni]",
"roman_letter": "ni"
},
{
"letter": "ニ",
"letter_name_ipa": "[ni]",
"letter_sound_ipa": "[ni]",
"roman_letter": "ni"
},
{
"letter": "ぬ",
"letter_name_ipa": "[nɯ]",
"letter_sound_ipa": "[nɯ]",
"roman_letter": "nu"
},
{
"letter": "ヌ",
"letter_name_ipa": "[nɯ]",
"letter_sound_ipa": "[nɯ]",
"roman_letter": "nu"
},
{
"letter": "ね",
"letter_name_ipa": "[ne]",
"letter_sound_ipa": "[ne]",
"roman_letter": "ne"
},
{
"letter": "ネ",
"letter_name_ipa": "[ne]",
"letter_sound_ipa": "[ne]",
"roman_letter": "ne"
},
{
"letter": "の",
"letter_name_ipa": "[no]",
"letter_sound_ipa": "[no]",
"roman_letter": "no"
},
{
"letter": "",
"letter_name_ipa": "[no]",
"letter_sound_ipa": "[no]",
"roman_letter": "no"
},
{
"letter": "は",
"letter_name_ipa": "[ha]",
"letter_sound_ipa": "[ha]",
"roman_letter": "ha"
},
{
"letter": "ハ",
"letter_name_ipa": "[ha]",
"letter_sound_ipa": "[ha]",
"roman_letter": "ha"
},
{
"letter": "ひ",
"letter_name_ipa": "[çi]",
"letter_sound_ipa": "[çi]",
"roman_letter": "hi"
},
{
"letter": "ヒ",
"letter_name_ipa": "[çi]",
"letter_sound_ipa": "[çi]",
"roman_letter": "hi"
},
{
"letter": "ふ",
"letter_name_ipa": "[ɸɯ]",
"letter_sound_ipa": "[ɸɯ]",
"roman_letter": "fu"
},
{
"letter": "フ",
"letter_name_ipa": "[ɸɯ]",
"letter_sound_ipa": "[ɸɯ]",
"roman_letter": "fu"
},
{
"letter": "へ",
"letter_name_ipa": "[he]",
"letter_sound_ipa": "[he]",
"roman_letter": "he"
},
{
"letter": "ヘ",
"letter_name_ipa": "[he]",
"letter_sound_ipa": "[he]",
"roman_letter": "he"
},
{
"letter": "ほ",
"letter_name_ipa": "[ho]",
"letter_sound_ipa": "[ho]",
"roman_letter": "ho"
},
{
"letter": "ホ",
"letter_name_ipa": "[ho]",
"letter_sound_ipa": "[ho]",
"roman_letter": "ho"
},
{
"letter": "ま",
"letter_name_ipa": "[ma]",
"letter_sound_ipa": "[ma]",
"roman_letter": "ma"
},
{
"letter": "マ",
"letter_name_ipa": "[ma]",
"letter_sound_ipa": "[ma]",
"roman_letter": "ma"
},
{
"letter": "み",
"letter_name_ipa": "[mi]",
"letter_sound_ipa": "[mi]",
"roman_letter": "mi"
},
{
"letter": "ミ",
"letter_name_ipa": "[mi]",
"letter_sound_ipa": "[mi]",
"roman_letter": "mi"
},
{
"letter": "む",
"letter_name_ipa": "[mɯ]",
"letter_sound_ipa": "[mɯ]",
"roman_letter": "mu"
},
{
"letter": "ム",
"letter_name_ipa": "[mɯ]",
"letter_sound_ipa": "[mɯ]",
"roman_letter": "mu"
},
{
"letter": "め",
"letter_name_ipa": "[me]",
"letter_sound_ipa": "[me]",
"roman_letter": "me"
},
{
"letter": "メ",
"letter_name_ipa": "[me]",
"letter_sound_ipa": "[me]",
"roman_letter": "me"
},
{
"letter": "も",
"letter_name_ipa": "[mo]",
"letter_sound_ipa": "[mo]",
"roman_letter": "mo"
},
{
"letter": "モ",
"letter_name_ipa": "[mo]",
"letter_sound_ipa": "[mo]",
"roman_letter": "mo"
},
{
"letter": "や",
"letter_name_ipa": "[ja]",
"letter_sound_ipa": "[ja]",
"roman_letter": "ya"
},
{
"letter": "ヤ",
"letter_name_ipa": "[ja]",
"letter_sound_ipa": "[ja]",
"roman_letter": "ya"
},
{
"letter": "ゆ",
"letter_name_ipa": "[jɯ]",
"letter_sound_ipa": "[jɯ]",
"roman_letter": "yu"
},
{
"letter": "ユ",
"letter_name_ipa": "[jɯ]",
"letter_sound_ipa": "[jɯ]",
"roman_letter": "yu"
},
{
"letter": "よ",
"letter_name_ipa": "[jo]",
"letter_sound_ipa": "[jo]",
"roman_letter": "yo"
},
{
"letter": "ヨ",
"letter_name_ipa": "[jo]",
"letter_sound_ipa": "[jo]",
"roman_letter": "yo"
},
{
"letter": "ら",
"letter_name_ipa": "[ɾa]",
"letter_sound_ipa": "[ɾa]",
"roman_letter": "ra"
},
{
"letter": "ラ",
"letter_name_ipa": "[ɾa]",
"letter_sound_ipa": "[ɾa]",
"roman_letter": "ra"
},
{
"letter": "り",
"letter_name_ipa": "[ɾi]",
"letter_sound_ipa": "[ɾi]",
"roman_letter": "ri"
},
{
"letter": "リ",
"letter_name_ipa": "[ɾi]",
"letter_sound_ipa": "[ɾi]",
"roman_letter": "ri"
},
{
"letter": "る",
"letter_name_ipa": "[ɾɯ]",
"letter_sound_ipa": "[ɾɯ]",
"roman_letter": "ru"
},
{
"letter": "ル",
"letter_name_ipa": "[ɾɯ]",
"letter_sound_ipa": "[ɾɯ]",
"roman_letter": "ru"
},
{
"letter": "れ",
"letter_name_ipa": "[ɾe]",
"letter_sound_ipa": "[ɾe]",
"roman_letter": "re"
},
{
"letter": "レ",
"letter_name_ipa": "[ɾe]",
"letter_sound_ipa": "[ɾe]",
"roman_letter": "re"
},
{
"letter": "ろ",
"letter_name_ipa": "[ɾo]",
"letter_sound_ipa": "[ɾo]",
"roman_letter": "ro"
},
{
"letter": "ロ",
"letter_name_ipa": "[ɾo]",
"letter_sound_ipa": "[ɾo]",
"roman_letter": "ro"
},
{
"letter": "わ",
"letter_name_ipa": "[wa]",
"letter_sound_ipa": "[wa]",
"roman_letter": "wa"
},
{
"letter": "ワ",
"letter_name_ipa": "[wa]",
"letter_sound_ipa": "[wa]",
"roman_letter": "wa"
},
{
"letter": "を",
"letter_name_ipa": "[o]",
"letter_sound_ipa": "[o]",
"roman_letter": "wo"
},
{
"letter": "ヲ",
"letter_name_ipa": "[o]",
"letter_sound_ipa": "[o]",
"roman_letter": "wo"
},
{
"letter": "ん",
"letter_name_ipa": "[n]",
"letter_sound_ipa": "[n], [m], [ŋ]",
"roman_letter": "n"
},
{
"letter": "ン",
"letter_name_ipa": "[n]",
"letter_sound_ipa": "[n], [m], [ŋ]",
"roman_letter": "n"
}
]

View File

@@ -0,0 +1,162 @@
[
{
"letter": "ئا",
"letter_name_ipa": "[ʔɑ]",
"letter_sound_ipa": "[ɑ]"
},
{
"letter": "ئە",
"letter_name_ipa": "[ʔæ]",
"letter_sound_ipa": "[æ]"
},
{
"letter": "ب",
"letter_name_ipa": "[bɛ]",
"letter_sound_ipa": "[b]"
},
{
"letter": "پ",
"letter_name_ipa": "[pɛ]",
"letter_sound_ipa": "[p]"
},
{
"letter": "ت",
"letter_name_ipa": "[tɛ]",
"letter_sound_ipa": "[t]"
},
{
"letter": "ج",
"letter_name_ipa": "[dʒɛ]",
"letter_sound_ipa": "[dʒ]"
},
{
"letter": "چ",
"letter_name_ipa": "[tʃɛ]",
"letter_sound_ipa": "[tʃ]"
},
{
"letter": "خ",
"letter_name_ipa": "[xɛ]",
"letter_sound_ipa": "[x]"
},
{
"letter": "د",
"letter_name_ipa": "[dɛ]",
"letter_sound_ipa": "[d]"
},
{
"letter": "ر",
"letter_name_ipa": "[rɛ]",
"letter_sound_ipa": "[r]"
},
{
"letter": "ز",
"letter_name_ipa": "[zɛ]",
"letter_sound_ipa": "[z]"
},
{
"letter": "ژ",
"letter_name_ipa": "[ʒɛ]",
"letter_sound_ipa": "[ʒ]"
},
{
"letter": "س",
"letter_name_ipa": "[sɛ]",
"letter_sound_ipa": "[s]"
},
{
"letter": "ش",
"letter_name_ipa": "[ʃɛ]",
"letter_sound_ipa": "[ʃ]"
},
{
"letter": "غ",
"letter_name_ipa": "[ʁɛ]",
"letter_sound_ipa": "[ʁ]"
},
{
"letter": "ف",
"letter_name_ipa": "[fɛ]",
"letter_sound_ipa": "[f]"
},
{
"letter": "ق",
"letter_name_ipa": "[qɛ]",
"letter_sound_ipa": "[q]"
},
{
"letter": "ك",
"letter_name_ipa": "[kɛ]",
"letter_sound_ipa": "[k]"
},
{
"letter": "گ",
"letter_name_ipa": "[gɛ]",
"letter_sound_ipa": "[g]"
},
{
"letter": "ڭ",
"letter_name_ipa": "[ŋɛ]",
"letter_sound_ipa": "[ŋ]"
},
{
"letter": "ل",
"letter_name_ipa": "[lɛ]",
"letter_sound_ipa": "[l]"
},
{
"letter": "م",
"letter_name_ipa": "[mɛ]",
"letter_sound_ipa": "[m]"
},
{
"letter": "ن",
"letter_name_ipa": "[nɛ]",
"letter_sound_ipa": "[n]"
},
{
"letter": "ھ",
"letter_name_ipa": "[hɛ]",
"letter_sound_ipa": "[h]"
},
{
"letter": "ئو",
"letter_name_ipa": "[ʔo]",
"letter_sound_ipa": "[o]"
},
{
"letter": "ئۇ",
"letter_name_ipa": "[ʔu]",
"letter_sound_ipa": "[u]"
},
{
"letter": "ئۆ",
"letter_name_ipa": "[ʔø]",
"letter_sound_ipa": "[ø]"
},
{
"letter": "ئۈ",
"letter_name_ipa": "[ʔy]",
"letter_sound_ipa": "[y]"
},
{
"letter": "ۋ",
"letter_name_ipa": "[wɛ]",
"letter_sound_ipa": "[w], [v]"
},
{
"letter": "ئې",
"letter_name_ipa": "[ʔe]",
"letter_sound_ipa": "[e]"
},
{
"letter": "ئى",
"letter_name_ipa": "[ʔi]",
"letter_sound_ipa": "[i]"
},
{
"letter": "ي",
"letter_name_ipa": "[jɛ]",
"letter_sound_ipa": "[j]"
}
]

9
public/changelog.txt Normal file
View File

@@ -0,0 +1,9 @@
2025.10.12 添加朗读器本地保存功能
2025.10.09 新增记忆字母表功能
2025.10.08 加快了TTS的生成速度将IPA生成设置为可选项
2025.10.07 新增文本朗读器优化了视频播放器UI
2025.10.06 更新了主页面UI移除IPA生成与文本朗读功能新增全语言翻译器
2025.10.05 新增IPA生成与文本朗读功能
2025.09.25 优化了主界面UI
2025.09.19 更新了单词板,单词不再会重叠

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M240-280v-320h-80v-80h160v400h-80Zm174 0 126-212-114-188h94l66 110 68-110h92L634-492l126 212h-94l-80-134-80 134h-92Z"/></svg>

After

Width:  |  Height:  |  Size: 241 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M360-360v-240h80v240h-80Zm160 0v-240h80v240h-80ZM480-40q-108 0-202.5-49.5T120-228v108H40v-240h240v80h-98q51 75 129.5 117.5T480-120q115 0 208.5-66T820-361l78 18q-45 136-160 219.5T480-40ZM42-520q7-67 32-128.5T143-762l57 57q-32 41-52 87.5T123-520H42Zm214-241-57-57q53-44 114-69.5T440-918v80q-51 5-97 25t-87 52Zm449 0q-41-32-87.5-52T520-838v-80q67 6 128.5 31T762-818l-57 57Zm133 241q-5-51-25-97.5T761-705l57-57q44 52 69 113.5T918-520h-80Z"/></svg>

After

Width:  |  Height:  |  Size: 559 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M380-300v-360l280 180-280 180ZM480-40q-108 0-202.5-49.5T120-228v108H40v-240h240v80h-98q51 75 129.5 117.5T480-120q115 0 208.5-66T820-361l78 18q-45 136-160 219.5T480-40ZM42-520q7-67 32-128.5T143-762l57 57q-32 41-52 87.5T123-520H42Zm214-241-57-57q53-44 114-69.5T440-918v80q-51 5-97 25t-87 52Zm449 0q-41-32-87.5-52T520-838v-80q67 6 128.5 31T762-818l-57 57Zm133 241q-5-51-25-97.5T761-705l57-57q44 52 69 113.5T918-520h-80Z"/></svg>

After

Width:  |  Height:  |  Size: 541 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>

After

Width:  |  Height:  |  Size: 222 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M120-220v-80h80v80h-80Zm0-140v-80h80v80h-80Zm0-140v-80h80v80h-80ZM260-80v-80h80v80h-80Zm100-160q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480Zm40 240v-80h80v80h-80Zm-200 0q-33 0-56.5-23.5T120-160h80v80Zm340 0v-80h80q0 33-23.5 56.5T540-80ZM120-640q0-33 23.5-56.5T200-720v80h-80Zm420 80Z"/></svg>

After

Width:  |  Height:  |  Size: 497 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z"/></svg>

After

Width:  |  Height:  |  Size: 319 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M240-400q-33 0-56.5-23.5T160-480q0-33 23.5-56.5T240-560q33 0 56.5 23.5T320-480q0 33-23.5 56.5T240-400Zm240 0q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm240 0q-33 0-56.5-23.5T640-480q0-33 23.5-56.5T720-560q33 0 56.5 23.5T800-480q0 33-23.5 56.5T720-400Z"/></svg>

After

Width:  |  Height:  |  Size: 427 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M520-200v-560h240v560H520Zm-320 0v-560h240v560H200Zm400-80h80v-400h-80v400Zm-320 0h80v-400h-80v400Zm0-400v400-400Zm320 0v400-400Z"/></svg>

After

Width:  |  Height:  |  Size: 254 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M320-200v-560l440 280-440 280Zm80-280Zm0 134 210-134-210-134v268Z"/></svg>

After

Width:  |  Height:  |  Size: 190 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"/></svg>

After

Width:  |  Height:  |  Size: 333 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M840-680v480q0 33-23.5 56.5T760-120H200q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h480l160 160Zm-80 34L646-760H200v560h560v-446ZM480-240q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35ZM240-560h360v-160H240v160Zm-40-86v446-560 114Z"/></svg>

After

Width:  |  Height:  |  Size: 388 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M120-280v-80h80v80h-80Zm400 0 120-200-120-200h80l80 133 80-133h80L720-480l120 200h-80l-80-133-80 133h-80Zm-280 0v-80h160v-80H240v-240h240v80H320v80h80q33 0 56.5 23.5T480-440v80q0 33-23.5 56.5T400-280H240Z"/></svg>

After

Width:  |  Height:  |  Size: 329 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="m520-280 120-200-120-200h80l80 133 80-133h80L720-480l120 200h-80l-80-133-80 133h-80Zm-360 0v-80h80v80h-80Zm160 0 80-320H240v-80h170q29 0 49.5 21.5T480-608l-2 18-78 310h-80Z"/></svg>

After

Width:  |  Height:  |  Size: 297 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M240-280v-80h80v80h-80Zm120 0v-160q0-33 23.5-56.5T440-520h60v-80H360v-80h140q33 0 56.5 23.5T580-600v80q0 33-23.5 56.5T500-440h-60v80h140v80H360Zm-240 0v-320H40v-80h160v400h-80Zm500 0 120-200-120-200h80l80 133 80-133h80L820-480l120 200h-80l-80-133-80 133h-80Z"/></svg>

After

Width:  |  Height:  |  Size: 383 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M240-280v-80h80v80h-80Zm-120 0v-320H40v-80h160v400h-80Zm500 0 120-200-120-200h80l80 133 80-133h80L820-480l120 200h-80l-80-133-80 133h-80Zm-260 0v-80h140v-80H360v-240h220v80H440v80h60q33 0 56.5 23.5T580-440v80q0 33-23.5 56.5T500-280H360Z"/></svg>

After

Width:  |  Height:  |  Size: 361 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M418-340q24 24 62 23.5t56-27.5l224-336-336 224q-27 18-28.5 55t22.5 61Zm62-460q59 0 113.5 16.5T696-734l-76 48q-33-17-68.5-25.5T480-720q-133 0-226.5 93.5T160-400q0 42 11.5 83t32.5 77h552q23-38 33.5-79t10.5-85q0-36-8.5-70T766-540l48-76q30 47 47.5 100T880-406q1 57-13 109t-41 99q-11 18-30 28t-40 10H204q-21 0-40-10t-30-28q-26-45-40-95.5T80-400q0-83 31.5-155.5t86-127Q252-737 325-768.5T480-800Zm7 313Z"/></svg>

After

Width:  |  Height:  |  Size: 521 B

1210
public/list_of_voices.json Normal file

File diff suppressed because it is too large Load Diff

1811
public/list_of_voices.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
import Button from "@/components/Button";
import IconClick from "@/components/IconClick";
import IMAGES from "@/config/images";
import { Letter, SupportedAlphabets } from "@/interfaces";
import { Dispatch, KeyboardEvent, SetStateAction, useEffect, useRef, useState } from "react";
export default function MemoryCard(
{
alphabet,
language,
setChosenAlphabet
}: {
alphabet: Letter[],
language: string,
setChosenAlphabet: Dispatch<SetStateAction<SupportedAlphabets | null>>
}
) {
const [index, setIndex] = useState(Math.floor(Math.random() * alphabet.length));
const [more, setMore] = useState(false);
const [ipaDisplay, setIPADisplay] = useState(true);
const [letterDisplay, setLetterDisplay] = useState(true);
useEffect(() => {
const handleKeydown = (e: globalThis.KeyboardEvent) => {
if (e.key === ' ') refresh();
}
document.addEventListener('keydown', handleKeydown);
return () => document.removeEventListener('keydown', handleKeydown);
});
const letter = alphabet[index];
const refresh = () => {
setIndex(Math.floor(Math.random() * alphabet.length));
}
return (
<div className="w-full flex justify-center items-center" onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => e.preventDefault()}>
<div className="m-4 p-4 w-full md:w-[60dvw] flex-col rounded-2xl shadow border-gray-200 border flex justify-center items-center">
<div className="w-full flex justify-end items-center">
<IconClick size={32} alt="close" src={IMAGES.close} onClick={() => setChosenAlphabet(null)}></IconClick>
</div>
<div className="flex flex-col gap-12 justify-center items-center">
<span className="text-7xl md:text-9xl">{letterDisplay ? letter.letter : ''}</span>
<span className="text-5xl md:text-7xl text-gray-400">{ipaDisplay ? letter.letter_sound_ipa : ''}</span>
</div>
<div className="flex flex-row mt-32 items-center justify-center gap-2">
<IconClick size={48} alt="refresh" src={IMAGES.refresh} onClick={refresh}></IconClick>
<IconClick size={48} alt="more" src={IMAGES.more_horiz} onClick={() => setMore(!more)}></IconClick>
{
more ? (<>
<Button className="w-20" label={letterDisplay ? '隐藏字母' : '显示字母'} onClick={() => { setLetterDisplay(!letterDisplay) }}></Button>
<Button className="w-20" label={ipaDisplay ? '隐藏IPA' : '显示IPA'} onClick={() => { setIPADisplay(!ipaDisplay) }}></Button>
</>) : (<></>)
}
</div>
</div>
</div>
);
}

70
src/app/alphabet/page.tsx Normal file
View File

@@ -0,0 +1,70 @@
'use client';
import Button from "@/components/Button";
import { Letter, SupportedAlphabets } from "@/interfaces";
import { useEffect, useState } from "react";
import MemoryCard from "./MemoryCard";
export default function Home() {
const [chosenAlphabet, setChosenAlphabet] = useState<SupportedAlphabets | null>(null);
const [alphabetData, setAlphabetData] = useState<Record<SupportedAlphabets, Letter[] | null>>({
japanese: null,
english: null,
esperanto: null,
uyghur: null
});
const [loadingState, setLoadingState] = useState<'idle' | 'loading' | 'success' | 'error'>('idle');
useEffect(() => {
if (chosenAlphabet && !alphabetData[chosenAlphabet]) {
setLoadingState('loading');
fetch('/alphabets/' + chosenAlphabet + '.json')
.then(res => {
if (!res.ok) throw new Error('Network response was not ok');
return res.json();
}).then((obj) => {
setAlphabetData(prev => ({ ...prev, [chosenAlphabet]: obj as Letter[] }));
setLoadingState('success');
}).catch(() => {
setLoadingState('error');
});
}
}, [chosenAlphabet, alphabetData]);
useEffect(() => {
if (loadingState === 'error') {
const timer = setTimeout(() => {
setLoadingState('idle');
setChosenAlphabet(null);
}, 2000);
return () => clearTimeout(timer);
}
}, [loadingState]);
if (!chosenAlphabet) return (
<div className="border border-gray-200 m-4 mt-4 flex flex-col justify-center items-center p-4 rounded-2xl gap-2">
<span className="text-2xl md:text-3xl"></span>
<div className="flex gap-1 flex-wrap">
<Button label="日语假名" onClick={() => setChosenAlphabet('japanese')}></Button>
<Button label="英文字母" onClick={() => setChosenAlphabet('english')}></Button>
<Button label="维吾尔字母" onClick={() => setChosenAlphabet('uyghur')}></Button>
<Button label="世界语字母" onClick={() => setChosenAlphabet('esperanto')}></Button>
</div>
</div>);
if (loadingState === 'loading') {
return '加载中...';
}
if (loadingState === 'error') {
return '加载失败,请重试';
}
if (loadingState === 'success' && alphabetData[chosenAlphabet]) {
return (<MemoryCard
language={chosenAlphabet}
alphabet={alphabetData[chosenAlphabet]}
setChosenAlphabet={setChosenAlphabet}>
</MemoryCard>);
}
return null;
}

64
src/app/api/ipa/route.ts Normal file
View File

@@ -0,0 +1,64 @@
import { callZhipuAPI } from "@/utils";
import { NextRequest, NextResponse } from "next/server";
async function getIPA(text: string) {
console.log(`get ipa of ${text}`);
const messages = [
{
role: 'user', content: `
请推断以下文本的语言生成对应的宽式国际音标IPA以及locale以JSON格式返回
[${text}]
结果如:
{
"ipa": "[ni˨˩˦ xɑʊ˨˩˦]",
"locale": "zh-CN"
}
注意:
直接返回json文本
ipa一定要加[]
locale如果可能有多个选取最可能的一个其中使用符号"-"
locale如果推断失败就返回{"locale": "en-US"}
`
}];
try {
const response = await callZhipuAPI(messages);
let to_parse = response.choices[0].message.content.trim() as string;
if (to_parse.startsWith('`')) to_parse = to_parse.slice(7, to_parse.length - 3);
if (to_parse.length === 0) throw Error('ai啥也每说');
return JSON.parse(to_parse);
} catch (error) {
console.error(error);
return null;
}
}
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get('text');
if (!text) {
return NextResponse.json(
{ error: "查询参数错误", message: "text参数是必需的" },
{ status: 400 }
);
}
const textInfo = await getIPA(text);
if (!textInfo) {
return NextResponse.json(
{ error: "服务暂时不可用", message: "LLM API 请求失败" },
{ status: 503 }
);
}
return NextResponse.json(textInfo, { status: 200 });
} catch (error) {
console.error('API 错误:', error);
return NextResponse.json(
{ error: "服务器内部错误", message: "请稍后重试" },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,62 @@
import { callZhipuAPI } from "@/utils";
import { NextRequest, NextResponse } from "next/server";
async function getLocale(text: string) {
console.log(`get locale of ${text}`);
const messages = [
{
role: 'user', content: `
请推断以下文本的的locale以JSON格式返回
[${text}]
结果如:
{
"locale": "zh-CN"
}
注意:
直接返回json文本
locale如果可能有多个选取最可能的一个其中使用符号"-"
locale如果推断失败就返回{"locale": "en-US"}
`
}];
try {
const response = await callZhipuAPI(messages);
let to_parse = response.choices[0].message.content.trim() as string;
if (to_parse.startsWith('`')) to_parse = to_parse.slice(7, to_parse.length - 3);
if (to_parse.length === 0) throw Error('ai啥也每说');
return JSON.parse(to_parse);
} catch (error) {
console.error(error);
return null;
}
}
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get('text');
if (!text) {
return NextResponse.json(
{ error: "查询参数错误", message: "text参数是必需的" },
{ status: 400 }
);
}
const textInfo = await getLocale(text.slice(0, 30));
if (!textInfo) {
return NextResponse.json(
{ error: "服务暂时不可用", message: "LLM API 请求失败" },
{ status: 503 }
);
}
return NextResponse.json(textInfo, { status: 200 });
} catch (error) {
console.error('API 错误:', error);
return NextResponse.json(
{ error: "服务器内部错误", message: "请稍后重试" },
{ status: 500 }
);
}
}

9
src/app/api/route.ts Normal file
View File

@@ -0,0 +1,9 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const url = request.url;
return NextResponse.json({
message: "Hello World",
url: url
}, { status: 200 });
}

View File

@@ -0,0 +1,64 @@
import { callZhipuAPI } from "@/utils";
import { NextRequest, NextResponse } from "next/server";
async function getTextinfo(text: string) {
console.log(`get textinfo of ${text}`);
const messages = [
{
role: 'user', content: `
请推断以下文本的语言、locale生成宽式国际音标IPA以JSON格式返回
[${text}]
结果如:
{
"text": "你好。",
"lang": "mandarin",
"ipa": "[ni˨˩˦ xɑʊ˨˩˦]",
"locale": "zh-CN"
}
注意:
直接返回json文本
ipa一定要加[]
lang的值是小写字母的英文的语言名称
locale如果可能有多个选取最可能的一个其中使用符号"-"
`
}];
try {
const response = await callZhipuAPI(messages);
let to_parse = response.choices[0].message.content.trim() as string;
if (to_parse.startsWith('`')) to_parse = to_parse.slice(7, to_parse.length - 3);
if (to_parse.length === 0) throw Error('ai啥也每说');
return JSON.parse(to_parse);
} catch (error) {
console.error(error);
return null;
}
}
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get('text');
if (!text) {
return NextResponse.json(
{ error: "查询参数错误", message: "text参数是必需的" },
{ status: 400 }
);
}
const textInfo = await getTextinfo(text);
if (!textInfo) {
return NextResponse.json(
{ error: "服务暂时不可用", message: "LLM API 请求失败" },
{ status: 503 }
);
}
return NextResponse.json(textInfo, { status: 200 });
} catch (error) {
console.error('API 错误:', error);
return NextResponse.json(
{ error: "服务器内部错误", message: "请稍后重试" },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,63 @@
import { callZhipuAPI } from "@/utils";
import { NextRequest, NextResponse } from "next/server";
async function translate(text: string, target_lang: string) {
console.log(`translate "${text}" into ${target_lang}`);
const messages = [
{
role: 'user', content: `
请推断以下文本的语言、locale并翻译到目标语言[${target_lang}]同样需要locale信息以JSON格式返回
[${text}]
结果如:
{
"source_locale": "zh-CN",
"target_locale": "de-DE",
"target_text": "Halo"
}
注意:
直接返回json文本
locale如果可能有多个选取最可能的一个其中使用符号"-"
locale如果推断失败就当作是en-US
`
}];
try {
const response = await callZhipuAPI(messages);
let to_parse = response.choices[0].message.content.trim() as string;
if (to_parse.startsWith('`')) to_parse = to_parse.slice(7, to_parse.length - 3);
if (to_parse.length === 0) throw Error('ai啥也每说');
return JSON.parse(to_parse);
} catch (error) {
console.error(error);
return null;
}
}
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get('text');
const target_lang = searchParams.get('target');
if (!text || !target_lang) {
return NextResponse.json(
{ error: "查询参数错误", message: "text参数, target参数是必需的" },
{ status: 400 }
);
}
const textInfo = await translate(text, target_lang);
if (!textInfo) {
return NextResponse.json(
{ error: "服务暂时不可用", message: "LLM API 请求失败" },
{ status: 503 }
);
}
return NextResponse.json(textInfo, { status: 200 });
} catch (error) {
console.error('API 错误:', error);
return NextResponse.json(
{ error: "服务器内部错误", message: "请稍后重试" },
{ status: 500 }
);
}
}

30
src/app/globals.css Normal file
View File

@@ -0,0 +1,30 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
/* @media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
} */
body {
background: var(--background);
color: var(--foreground);
font-family: var(--font-geist-sans), Arial, Helvetica, sans-serif;
}
.code-block {
font-family: var(--font-geist-mono), monospace;
}

71
src/app/layout.tsx Normal file
View File

@@ -0,0 +1,71 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import type { Viewport } from 'next'
import Link from "next/link";
import Image from "next/image";
export const viewport: Viewport = {
width: 'device-width',
initialScale: 1.0
}
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Learn Languages",
description: "A Website to Learn Languages",
};
function MyLink(
{ href, label }: { href: string, label: string }
) {
return (
<Link className="font-bold" href={href}>{label}</Link>
)
}
function Navbar() {
return (
<div className="flex justify-between items-center w-full h-16 px-8 bg-[#35786f] text-white">
<Link href={'/'} className="text-xl flex">
<Image
src={'/favicon.ico'}
alt="logo"
width="32"
height="32"
className="rounded-4xl">
</Image>
<span className="font-bold"></span>
</Link>
<div className="flex gap-4 text-xl">
<MyLink href="/changelog.txt" label="关于"></MyLink>
<MyLink href="https://github.com/GoddoNebianU/learn-languages" label="源码"></MyLink>
</div>
</div>
);
}
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<Navbar></Navbar>
{children}
</body>
</html>
);
}

99
src/app/page.tsx Normal file
View File

@@ -0,0 +1,99 @@
import Link from "next/link";
function TopArea() {
return (
<div className="bg-[#35786f] text-white w-full min-h-[75dvh] flex justify-center items-center">
<div className="mb-16 mx-16 md:mx-0 md:max-w-[60dvw]">
<h1 className="text-6xl md:text-9xl mb-8">Learn Languages</h1>
<p className="text-2xl md:text-5xl">Here is a very useful website to help you learn almost every language in the world, including constructed ones.</p>
</div>
</div>
)
}
interface LinkAreaProps {
href: string,
name: string,
description: string,
color: string
}
function LinkArea(
{ href, name, description, color }: LinkAreaProps
) {
return (
<Link href={href}
style={{ backgroundColor: color }}
className={`h-32 md:h-64 flex justify-center items-center`}>
<div className="text-white m-8">
<h1 className="text-4xl">{name}</h1>
<p className="text-xl">{description}</p>
</div>
</Link>
);
}
function LinkGrid() {
return (
<div className="w-full grid grid-cols-1 grid-rows-6 md:grid-cols-3">
<LinkArea
href="/translator"
name="翻译器"
description="翻译到任何语言并标注国际音标IPA"
color="#a56068"></LinkArea>
<LinkArea
href="/text-speaker"
name="朗读器"
description="识别并朗读文本,支持循环朗读、朗读速度调节"
color="#578aad"></LinkArea>
{/* <LinkArea
href="/word-board"
name="词墙"
description="将单词固定到一片区域,高效便捷地记忆单词"
color="#e9b353"></LinkArea> */}
<LinkArea
href="/srt-player"
name="逐句视频播放器"
description="基于SRT字幕文件逐句播放视频以模仿母语者的发音"
color="#3c988d"></LinkArea>
<LinkArea
href="/alphabet"
name="记忆字母表"
description="从字母表开始新语言的学习"
color="#dd7486"></LinkArea>
<LinkArea
href="#"
name="更多功能"
description="开发中,敬请期待"
color="#cab48a"></LinkArea>
</div>
)
}
function Fortune() {
return (
<div className="w-full flex justify-center font-serif items-center flex-col min-h-64 h-[25vdh]">
<p className="text-3xl">Stay hungry, stay foolish.</p>
<cite className="text-[#e9b353] text-xl"> Steve Jobs</cite>
</div>
);
}
function Explore() {
return (
<div className="bg-[#bbbbbb] w-full flex justify-center items-center flex-col h-52">
<span className="text-[100px] text-white"></span>
<div className="w-0 h-0 border-l-[40px] border-r-[40px] border-t-[30px] border-l-transparent border-r-transparent border-t-white"></div>
</div>
);
}
export default function Home() {
return (
<>
<TopArea></TopArea>
<Fortune></Fortune>
<Explore></Explore>
<LinkGrid></LinkGrid>
</>);
}

View File

@@ -0,0 +1,53 @@
import Button from "@/components/Button";
import { useRef, useState } from "react";
export default function UploadArea(
{
setVideoUrl,
setSrtUrl
}: {
setVideoUrl: (url: string | null) => void;
setSrtUrl: (url: string | null) => void;
}
) {
const inputRef = useRef<HTMLInputElement>(null);
const [videoFile, setVideoFile] = useState<File | null>(null);
const [SrtFile, setSrtFile] = useState<File | null>(null);
const uploadVideo = () => {
const input = inputRef.current;
if (input) {
input.setAttribute('accept', 'video/*');
input.click();
input.onchange = () => {
const file = input.files?.[0];
if (file) {
setVideoFile(file);
setVideoUrl(URL.createObjectURL(file));
}
};
}
}
const uploadSRT = () => {
const input = inputRef.current;
if (input) {
input.setAttribute('accept', '.srt');
input.click();
input.onchange = () => {
const file = input.files?.[0];
if (file) {
setSrtFile(file);
setSrtUrl(URL.createObjectURL(file));
}
};
}
}
return (
<div className="w-full flex flex-col gap-2 m-2">
<Button label="上传视频" onClick={uploadVideo} />
<Button label="上传字幕" onClick={uploadSRT} />
<input type="file" className="hidden" ref={inputRef} />
</div >
)
}

View File

@@ -0,0 +1,21 @@
import { inspect } from "@/utils";
export default function SubtitleDisplay({ subtitle }: { subtitle: string }) {
const words = subtitle.match(/\b[\w']+(?:-[\w']+)*\b/g) || [];
let i = 0;
return (
<div className="w-full subtitle overflow-auto h-16 mt-2 break-words bg-black/50 font-sans text-white text-center text-2xl">
{
words.map((v) => (
<span
onClick={inspect(v)}
key={i++}
className="hover:bg-gray-700 hover:underline hover:cursor-pointer"
>
{v + ' '}
</span>
))
}
</div>
);
}

View File

@@ -0,0 +1,179 @@
import { useState, useRef, forwardRef, useEffect, KeyboardEvent, useCallback } from "react";
import SubtitleDisplay from "./SubtitleDisplay";
import Button from "@/components/Button";
import { getIndex, parseSrt, getNearistIndex } from "../subtitle";
type VideoPanelProps = {
videoUrl: string | null;
srtUrl: string | null;
};
const VideoPanel = forwardRef<HTMLVideoElement, VideoPanelProps>((
{ videoUrl, srtUrl }, videoRef
) => {
videoRef = videoRef as React.RefObject<HTMLVideoElement>;
const [isPlaying, setIsPlaying] = useState<boolean>(false);
const [srtLength, setSrtLength] = useState<number>(0);
const [progress, setProgress] = useState<number>(-1);
const [autoPause, setAutoPause] = useState<boolean>(true);
const [spanText, setSpanText] = useState<string>('');
const [subtitle, setSubtitle] = useState<string>('');
const parsedSrtRef = useRef<{ start: number; end: number; text: string; }[] | null>(null);
const rafldRef = useRef<number>(0);
const ready = useRef({
'vid': false,
'sub': false,
'all': function () { return this.vid && this.sub }
});
const togglePlayPause = useCallback(() => {
if (!videoUrl) return;
const video = videoRef.current;
if (!video) return;
if (video.paused || video.currentTime === 0) {
video.play();
} else {
video.pause();
}
setIsPlaying(!video.paused);
}, [videoRef, videoUrl]);
useEffect(() => {
const handleKeyDownEvent = (e: globalThis.KeyboardEvent) => {
if (e.key === 'n') {
next();
} else if (e.key === 'p') {
previous();
} else if (e.key === ' ') {
togglePlayPause();
} else if (e.key === 'r') {
restart();
} else if (e.key === 'a') {
; handleAutoPauseToggle();
}
}
document.addEventListener('keydown', handleKeyDownEvent);
return () => document.removeEventListener('keydown', handleKeyDownEvent)
});
useEffect(() => {
const cb = () => {
if (ready.current.all()) {
if (!parsedSrtRef.current) {
;
} else if (isPlaying) {
// 这里负责显示当前时间的字幕与自动暂停
const srt = parsedSrtRef.current;
const ct = videoRef.current?.currentTime as number;
const index = getIndex(srt, ct);
if (index !== null) {
setSubtitle(srt[index].text)
if (autoPause && ct >= (srt[index].end - 0.05) && ct < srt[index].end) {
videoRef.current!.currentTime = srt[index].start;
togglePlayPause();
}
} else {
setSubtitle('');
}
} else {
;
}
}
rafldRef.current = requestAnimationFrame(cb);
}
rafldRef.current = requestAnimationFrame(cb);
return () => {
cancelAnimationFrame(rafldRef.current);
}
}, [autoPause, isPlaying, togglePlayPause, videoRef]);
useEffect(() => {
if (videoUrl && videoRef.current) {
videoRef.current.src = videoUrl;
videoRef.current.load();
setIsPlaying(false);
ready.current['vid'] = true;
}
}, [videoRef, videoUrl]);
useEffect(() => {
if (srtUrl) {
fetch(srtUrl)
.then(response => response.text())
.then(data => {
parsedSrtRef.current = parseSrt(data);
setSrtLength(parsedSrtRef.current.length);
ready.current['sub'] = true;
});
}
}, [srtUrl]);
const timeUpdate = () => {
if (!parsedSrtRef.current || !videoRef.current) return;
const index = getIndex(parsedSrtRef.current, videoRef.current.currentTime);
if (!index) return;
setSpanText(`${index + 1}/${parsedSrtRef.current.length}`)
}
const handleSeek = (e: React.ChangeEvent<HTMLInputElement>) => {
if (videoRef.current && parsedSrtRef.current) {
const newProgress = parseInt(e.target.value);
videoRef.current.currentTime = parsedSrtRef.current[newProgress]?.start || 0;
setProgress(newProgress);
}
};
const handleAutoPauseToggle = () => {
setAutoPause(!autoPause);
};
const next = () => {
if (!parsedSrtRef.current || !videoRef.current) return;
const i = getNearistIndex(parsedSrtRef.current, videoRef.current.currentTime);
if (i != null && i + 1 < parsedSrtRef.current.length) {
videoRef.current.currentTime = parsedSrtRef.current[i + 1].start;
videoRef.current.play();
setIsPlaying(true);
}
}
const previous = () => {
if (!parsedSrtRef.current || !videoRef.current) return;
const i = getNearistIndex(parsedSrtRef.current, videoRef.current.currentTime);
if (i != null && i - 1 >= 0) {
videoRef.current.currentTime = parsedSrtRef.current[i - 1].start;
videoRef.current.play();
setIsPlaying(true);
}
}
const restart = () => {
if (!parsedSrtRef.current || !videoRef.current) return;
const i = getNearistIndex(parsedSrtRef.current, videoRef.current.currentTime);
if (i != null && i >= 0) {
videoRef.current.currentTime = parsedSrtRef.current[i].start;
videoRef.current.play();
setIsPlaying(true);
}
}
return (
<div className="w-full flex flex-col">
<video className="bg-gray-200" ref={videoRef} onTimeUpdate={timeUpdate}></video>
<SubtitleDisplay subtitle={subtitle}></SubtitleDisplay>
<div className="buttons flex mt-2 gap-2 flex-wrap">
<Button label={isPlaying ? '暂停' : '播放'} onClick={togglePlayPause}></Button>
<Button label="上句" onClick={previous}></Button>
<Button label="下句" onClick={next}></Button>
<Button label="句首" onClick={restart}></Button>
<Button label={`自动暂停(${autoPause ? '是' : '否'})`} onClick={handleAutoPauseToggle}></Button>
</div>
<input className="seekbar" type="range" min={0} max={srtLength} onChange={handleSeek} step={1} value={progress}></input>
<span>{spanText}</span>
</div>
);
});
VideoPanel.displayName = 'VideoPanel';
export default VideoPanel;

View File

@@ -0,0 +1,25 @@
'use client';
import { KeyboardEvent, useRef, useState } from "react";
import UploadArea from "./UploadArea";
import VideoPanel from "./VideoPlayer/VideoPanel";
export default function Home() {
const videoRef = useRef<HTMLVideoElement>(null);
const [videoUrl, setVideoUrl] = useState<string | null>(null);
const [srtUrl, setSrtUrl] = useState<string | null>(null);
return (
<div className="flex w-screen pt-8 items-center justify-center" onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => e.preventDefault()}>
<div className="w-[80vw] md:w-[45vw] flex items-center flex-col">
<VideoPanel
videoUrl={videoUrl}
srtUrl={srtUrl}
ref={videoRef} />
<UploadArea
setVideoUrl={setVideoUrl}
setSrtUrl={setSrtUrl} />
</div>
</div>
);
}

View File

@@ -0,0 +1,52 @@
export function parseSrt(data: string) {
const lines = data.split(/\r?\n/);
const result = [];
const re = new RegExp('(\\d{2}:\\d{2}:\\d{2},\\d{3})\\s*-->\\s*(\\d{2}:\\d{2}:\\d{2},\\d{3})');
let i = 0;
while (i < lines.length) {
if (!lines[i].trim()) { i++; continue; }
i++;
if (i >= lines.length) break;
const timeMatch = lines[i].match(re);
if (!timeMatch) { i++; continue; }
const start = toSeconds(timeMatch[1]);
const end = toSeconds(timeMatch[2]);
i++;
let text = '';
while (i < lines.length && lines[i].trim()) {
text += lines[i] + '\n';
i++;
}
result.push({ start, end, text: text.trim() });
i++;
}
return result;
}
export function getNearistIndex(srt: { start: number; end: number; text: string; }[], ct: number) {
for (let i = 0; i < srt.length; i++) {
const s = srt[i];
const l = ct - s.start >= 0;
const r = ct - s.end >= 0;
if (!(l || r)) return i - 1;
if (l && (!r)) return i;
}
}
export function getIndex(srt: { start: number; end: number; text: string; }[], ct: number) {
for (let i = 0; i < srt.length; i++) {
if (ct >= srt[i].start && ct <= srt[i].end) {
return i;
}
}
return null;
}
export function getSubtitle(srt: { start: number; end: number; text: string; }[], currentTime: number) {
return srt.find(sub => currentTime >= sub.start && currentTime <= sub.end) || null;
}
function toSeconds(timeStr: string): number {
const [h, m, s] = timeStr.replace(',', '.').split(':');
return parseFloat((parseInt(h) * 3600 + parseInt(m) * 60 + parseFloat(s)).toFixed(3));
}

View File

@@ -0,0 +1,94 @@
'use client';
import { getTextSpeakerData, setTextSpeakerData } from "@/utils";
import { useState } from "react";
import z from "zod";
import { TextSpeakerItemSchema } from "@/interfaces";
import IconClick from "@/components/IconClick";
import IMAGES from "@/config/images";
interface TextCardProps {
item: z.infer<typeof TextSpeakerItemSchema>;
handleUse: (item: z.infer<typeof TextSpeakerItemSchema>) => void;
handleDel: (item: z.infer<typeof TextSpeakerItemSchema>) => void;
}
function TextCard({
item,
handleUse,
handleDel
}: TextCardProps) {
const onUseClick = () => {
handleUse(item);
}
const onDelClick = () => {
handleDel(item);
}
return (
<div className="hover:cursor-pointer p-2 border-b-1 border-gray-200 rounded-2xl bg-gray-100 m-2 grid grid-cols-8" onClick={onUseClick}>
<div className="col-span-7">
<div className="max-h-26 text-3xl overflow-y-auto">{item.text}</div>
<div className="max-h-16 overflow-y-auto text-xl text-gray-600 whitespace-nowrap overflow-x-auto">{item.ipa}</div>
</div>
<div className="flex justify-center items-center border-gray-300 border-l-2 m-2">
<IconClick
src={IMAGES.delete}
alt="delete"
onClick={onDelClick}
className="place-self-center"
size={42}>
</IconClick>
</div>
</div>
);
}
interface SaveListProps {
show?: boolean;
handleUse: (item: z.infer<typeof TextSpeakerItemSchema>) => void;
}
export default function SaveList({
show = false,
handleUse
}: SaveListProps) {
const [data, setData] = useState(getTextSpeakerData());
const handleDel = (item: z.infer<typeof TextSpeakerItemSchema>) => {
const current_data = getTextSpeakerData();
current_data.splice(
current_data.findIndex(v => v.text === item.text)
);
setTextSpeakerData(current_data);
}
const refresh = () => {
setData(getTextSpeakerData());
}
const handleDeleteAll = () => {
const yesorno = prompt('确定删光吗?(Y/N)')?.trim();
if (yesorno && (yesorno === 'Y' || yesorno === 'y')) {
setTextSpeakerData([]);
refresh();
}
}
if (show) return (
<div className="my-4 p-2 mx-4 md:mx-32 border-1 border-gray-200 rounded-2xl" style={{ fontFamily: 'Times New Roman, serif' }}>
<div className="flex flex-row justify-center gap-8 items-center">
<IconClick
src={IMAGES.refresh}
alt="refresh"
onClick={refresh}
size={48}
className=""></IconClick>
<IconClick
src={IMAGES.delete}
alt="delete"
onClick={handleDeleteAll}
size={48}
className=""></IconClick>
</div>
<ul>
{data.map(v =>
<TextCard item={v} key={crypto.randomUUID()} handleUse={handleUse} handleDel={handleDel}></TextCard>
)}
</ul>
</div>
); else return (<></>);
}

View File

@@ -0,0 +1,301 @@
"use client";
import Button from "@/components/Button";
import IconClick from "@/components/IconClick";
import IMAGES from "@/config/images";
import { useAudioPlayer } from "@/hooks/useAudioPlayer";
import { getTextSpeakerData, getTTSAudioUrl, setTextSpeakerData } from "@/utils";
import { ChangeEvent, useEffect, useRef, useState } from "react";
import SaveList from "./SaveList";
import { TextSpeakerItemSchema } from "@/interfaces";
import z from "zod";
export default function Home() {
const textareaRef = useRef<HTMLTextAreaElement>(null);
const [showSpeedAdjust, setShowSpeedAdjust] = useState(false);
const [showSaveList, setShowSaveList] = useState(false);
const [saving, setSaving] = useState(false);
const [ipaEnabled, setIPAEnabled] = useState(false);
const [speed, setSpeed] = useState(1);
const [pause, setPause] = useState(true);
const [autopause, setAutopause] = useState(true);
const textRef = useRef('');
const [locale, setLocale] = useState<string | null>(null);
const [ipa, setIPA] = useState<string>('');
const objurlRef = useRef<string | null>(null);
const [processing, setProcessing] = useState(false);
const [voicesData, setVoicesData] = useState<{
locale: string,
short_name: string
}[] | null>(null);
const [loading, setLoading] = useState(true);
const { playAudio, stopAudio, audioRef } = useAudioPlayer();
useEffect(() => {
fetch('/list_of_voices.json')
.then(res => res.json())
.then(setVoicesData)
.catch(() => setVoicesData(null))
.finally(() => setLoading(false));
}, []);
useEffect(() => {
const audio = audioRef.current;
if (!audio) return;
const handleEnded = () => {
if (autopause) {
setPause(true);
} else {
playAudio(objurlRef.current!);
}
}
audio.addEventListener('ended', handleEnded);
return () => {
audio.removeEventListener('ended', handleEnded);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [audioRef, autopause]);
if (loading) return <div>...</div>;
if (!voicesData) return <div></div>;
const speak = async () => {
if (processing) return;
setProcessing(true);
if (ipa.length === 0 && ipaEnabled && textRef.current.length !== 0) {
const params = new URLSearchParams({
text: textRef.current
});
fetch(`/api/ipa?${params}`)
.then(res => res.json())
.then(data => {
setIPA(data.ipa);
}).catch(e => {
console.error(e);
setIPA('');
})
}
if (pause) {
// 如果没在读
if (textRef.current.length === 0) {
// 没文本咋读
} else {
setPause(false);
if (objurlRef.current) {
// 之前有播放
playAudio(objurlRef.current);
} else {
// 第一次播放
try {
let theLocale = locale;
if (!theLocale) {
console.log('downloading text info');
const params = new URLSearchParams({
text: textRef.current.slice(0, 30)
});
const textinfo = await (await fetch(`/api/locale?${params}`)).json();
setLocale(textinfo.locale);
theLocale = textinfo.locale as string;
}
const voice = voicesData.find(v => v.locale.startsWith(theLocale));
if (!voice) throw 'Voice not found.';
objurlRef.current = await getTTSAudioUrl(
textRef.current,
voice.short_name,
(() => {
if (speed === 1) return {};
else if (speed < 1) return {
rate: `-${100 - speed * 100}%`
}; else return {
rate: `+${speed * 100 - 100}%`
};
})()
);
playAudio(objurlRef.current);
} catch (e) {
console.error(e);
setPause(true);
setLocale(null);
setProcessing(false);
}
}
}
} else {
// 如果在读就暂停
setPause(true);
stopAudio();
}
setProcessing(false);
}
const handleInputChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
textRef.current = e.target.value.trim();
setLocale(null);
setIPA('');
if (objurlRef.current) URL.revokeObjectURL(objurlRef.current);
objurlRef.current = null;
stopAudio();
setPause(true);
}
const letMeSetSpeed = (new_speed: number) => {
return () => {
setSpeed(new_speed);
if (objurlRef.current) URL.revokeObjectURL(objurlRef.current);
objurlRef.current = null;
stopAudio();
setPause(true);
}
}
const handleUseItem = (item: z.infer<typeof TextSpeakerItemSchema>) => {
if (textareaRef.current) textareaRef.current.value = item.text;
textRef.current = item.text;
setLocale(item.locale);
setIPA(item.ipa || '');
if (objurlRef.current) URL.revokeObjectURL(objurlRef.current);
objurlRef.current = null;
stopAudio();
setPause(true);
}
const save = async () => {
if (saving) return;
if (textRef.current.length === 0) return;
setSaving(true);
try {
let theLocale = locale;
if (!theLocale) {
console.log('downloading text info');
const params = new URLSearchParams({
text: textRef.current.slice(0, 30)
});
const textinfo = await (await fetch(`/api/locale?${params}`)).json();
setLocale(textinfo.locale);
theLocale = textinfo.locale as string;
}
let theIPA = ipa;
if (ipa.length === 0 && ipaEnabled) {
const params = new URLSearchParams({
text: textRef.current
});
const tmp = await (await fetch(`/api/ipa?${params}`)).json();
setIPA(tmp.ipa);
theIPA = tmp.ipa;
}
const save = getTextSpeakerData();
const oldIndex = save.findIndex(v => v.text === textRef.current);
if (oldIndex !== -1) {
const oldItem = save[oldIndex];
if (theIPA) {
if ((!oldItem.ipa || (oldItem.ipa !== theIPA))) {
oldItem.ipa = theIPA;
setTextSpeakerData(save);
}
}
} else if (theIPA.length === 0) {
save.push({
text: textRef.current,
locale: theLocale
});
} else {
save.push({
text: textRef.current,
locale: theLocale,
ipa: theIPA
});
}
setTextSpeakerData(save);
} catch (e) {
console.error(e);
setLocale(null);
} finally {
setSaving(false);
}
}
return (<>
<div className="my-4 p-4 mx-4 md:mx-32 border-1 border-gray-200 rounded-2xl" style={{ fontFamily: 'Times New Roman, serif' }}>
<textarea className="text-2xl resize-none focus:outline-0 min-h-64 w-full border-gray-200 border-b"
onChange={handleInputChange}
ref={textareaRef}>
</textarea>
{
ipa.length !== 0 && (<div className="overflow-auto text-gray-600 h-18 border-gray-200 border-b">
{ipa}
</div>) || (<div className="h-18"></div>)
}
<div className="mt-8 relative w-full flex flex-row flex-wrap gap-2 justify-center items-center">
{showSpeedAdjust && (
<div className="bg-white p-6 rounded-2xl border-gray-200 border-2 shadow-2xl absolute left-1/2 -translate-x-1/2 -translate-y-full -top-4 flex flex-row flex-wrap gap-2 justify-center items-center">
<IconClick size={45} onClick={letMeSetSpeed(0.5)}
src={IMAGES.speed_0_5x}
alt="0.5x"
className={speed === 0.5 ? 'bg-gray-200' : ''}
></IconClick>
<IconClick size={45} onClick={letMeSetSpeed(0.7)}
src={IMAGES.speed_0_7x}
alt="0.7x"
className={speed === 0.7 ? 'bg-gray-200' : ''}
></IconClick>
<IconClick size={45} onClick={letMeSetSpeed(1)}
src={IMAGES.speed_1x}
alt="1x"
className={speed === 1 ? 'bg-gray-200' : ''}
></IconClick>
<IconClick size={45} onClick={letMeSetSpeed(1.2)}
src={IMAGES.speed_1_2_x}
alt="1.2x"
className={speed === 1.2 ? 'bg-gray-200' : ''}
></IconClick>
<IconClick size={45} onClick={letMeSetSpeed(1.5)}
src={IMAGES.speed_1_5x}
alt="1.5x"
className={speed === 1.5 ? 'bg-gray-200' : ''}
></IconClick>
</div>)}
<IconClick size={45} onClick={speak} src={
pause ? IMAGES.play_arrow : IMAGES.pause
} alt="playorpause" className={`${processing ? 'bg-gray-200' : ''}`}></IconClick>
<IconClick size={45} onClick={() => {
setAutopause(!autopause); if (objurlRef) { stopAudio(); } setPause(true);
}} src={
autopause ? IMAGES.autoplay : IMAGES.autopause
} alt="autoplayorpause"
></IconClick>
<IconClick size={45} onClick={() => setShowSpeedAdjust(!showSpeedAdjust)}
src={IMAGES.speed}
alt="speed"
className={`${showSpeedAdjust ? 'bg-gray-200' : ''}`}></IconClick>
<IconClick size={45} onClick={save}
src={IMAGES.save}
alt="save"
className={`${saving ? 'bg-gray-200' : ''}`}></IconClick>
<div className="w-full flex flex-row flex-wrap gap-2 justify-center items-center">
<Button label="生成IPA"
selected={ipaEnabled}
onClick={() => setIPAEnabled(!ipaEnabled)}>
</Button>
<Button label="查看保存项"
onClick={() => { setShowSaveList(!showSaveList) }}
selected={showSaveList}>
</Button>
</div>
</div>
</div>
<SaveList show={showSaveList} handleUse={handleUseItem}></SaveList>
</>);
}

243
src/app/translator/page.tsx Normal file
View File

@@ -0,0 +1,243 @@
"use client";
import { ChangeEvent, useEffect, useState } from "react";
import Button from "@/components/Button";
import IconClick from "@/components/IconClick";
import { useAudioPlayer } from "@/hooks/useAudioPlayer";
import IMAGES from "@/config/images";
import { getTTSAudioUrl } from "@/utils";
export default function Home() {
const [ipaEnabled, setIPAEnabled] = useState(true);
const [voicesData, setVoicesData] = useState<{
locale: string,
short_name: string
}[] | null>(null);
const [loading, setLoading] = useState(true);
const [targetLang, setTargetLang] = useState('Italian');
const [sourceText, setSourceText] = useState('');
const [targetText, setTargetText] = useState('');
const [sourceIPA, setSourceIPA] = useState('');
const [targetIPA, setTargetIPA] = useState('');
const [sourceLocale, setSourceLocale] = useState<string | null>(null);
const [targetLocale, setTargetLocale] = useState<string | null>(null);
const [translating, setTranslating] = useState(false);
const { playAudio } = useAudioPlayer();
useEffect(() => {
fetch('/list_of_voices.json')
.then(res => res.json())
.then(setVoicesData)
.catch(() => setVoicesData(null))
.finally(() => setLoading(false));
}, []);
if (loading) return <div>...</div>;
if (!voicesData) return <div></div>;
const tl = ['English', 'Italian', 'Japanese'];
const inputLanguage = () => {
const lang = prompt('Input a language.')?.trim();
if (lang) {
setTargetLang(lang);
}
}
const translate = () => {
if (translating) return;
if (sourceText.length === 0) return;
setTranslating(true);
setTargetText('');
setSourceLocale(null);
setTargetLocale(null);
setSourceIPA('');
setTargetIPA('');
const params = new URLSearchParams({
text: sourceText,
target: targetLang
})
fetch(`/api/translate?${params}`)
.then(res => res.json())
.then(obj => {
setSourceLocale(obj.source_locale);
setTargetLocale(obj.target_locale);
setTargetText(obj.target_text);
if (ipaEnabled) {
const params = new URLSearchParams({
text: sourceText
});
fetch(`/api/ipa?${params}`)
.then(res => res.json())
.then(data => {
setSourceIPA(data.ipa);
}).catch(e => {
console.error(e);
setSourceIPA('');
})
const params2 = new URLSearchParams({
text: obj.target_text
});
fetch(`/api/ipa?${params2}`)
.then(res => res.json())
.then(data => {
setTargetIPA(data.ipa);
}).catch(e => {
console.error(e);
setTargetIPA('');
})
}
}).catch(r => {
console.error(r);
setSourceLocale('');
setTargetLocale('');
setTargetText('');
}).finally(() => setTranslating(false));
}
const handleInputChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
setSourceText(e.target.value.trim());
setTargetText('');
setSourceLocale(null);
setTargetLocale(null);
setSourceIPA('');
setTargetIPA('');
}
const readSource = async () => {
if (sourceText.length === 0) return;
if (sourceIPA.length === 0 && ipaEnabled) {
const params = new URLSearchParams({
text: sourceText
});
fetch(`/api/ipa?${params}`)
.then(res => res.json())
.then(data => {
setSourceIPA(data.ipa);
}).catch(e => {
console.error(e);
setSourceIPA('');
})
}
if (!sourceLocale) {
try {
const params = new URLSearchParams({
text: sourceText.slice(0, 30)
});
const res = await fetch(`/api/locale?${params}`);
const info = await res.json();
setSourceLocale(info.locale);
const voice = voicesData.find(v => v.locale.startsWith(info.locale));
if (!voice) {
return;
}
const url = await getTTSAudioUrl(sourceText, voice.short_name);
await playAudio(url);
URL.revokeObjectURL(url);
} catch (e) {
console.error(e);
setSourceLocale(null);
return;
}
} else {
const voice = voicesData.find(v => v.locale.startsWith(sourceLocale!));
if (!voice) {
return;
}
const url = await getTTSAudioUrl(sourceText, voice.short_name);
await playAudio(url);
URL.revokeObjectURL(url);
}
}
const readTarget = async () => {
if (targetText.length === 0) return;
if (targetIPA.length === 0 && ipaEnabled) {
const params = new URLSearchParams({
text: targetText
});
fetch(`/api/ipa?${params}`)
.then(res => res.json())
.then(data => {
setTargetIPA(data.ipa);
}).catch(e => {
console.error(e);
setTargetIPA('');
})
}
const voice = voicesData.find(v => v.locale.startsWith(targetLocale!));
if (!voice) return;
const url = await getTTSAudioUrl(targetText, voice.short_name);
await playAudio(url);
URL.revokeObjectURL(url);
}
return (
<>
<div className="w-screen flex flex-col md:flex-row md:justify-between gap-2 p-2">
<div className="card1 w-full md:w-1/2 flex flex-col-reverse gap-2">
<div className="textarea1 border-1 border-gray-200 rounded-2xl w-full h-64 p-2">
<textarea onChange={handleInputChange} className="resize-none h-8/12 w-full focus:outline-0"></textarea>
<div className="ipa w-full h-2/12 overflow-auto text-gray-600">
{sourceIPA}
</div>
<div className="h-2/12 w-full flex justify-end items-center">
<IconClick onClick={async () => {
if (sourceText.length !== 0)
await navigator.clipboard.writeText(sourceText);
}} src={IMAGES.copy_all} alt="copy"></IconClick>
<IconClick onClick={readSource} src={IMAGES.play_arrow} alt="play"></IconClick>
</div>
</div>
<div className="option1 w-full flex flex-row justify-between items-center">
<span>detect language</span>
<Button label="generate ipa" selected={ipaEnabled} onClick={() => setIPAEnabled(!ipaEnabled)}></Button>
</div>
</div>
<div className="card2 w-full md:w-1/2 flex flex-col-reverse gap-2">
<div className="textarea2 bg-gray-100 rounded-2xl w-full h-64 p-2">
<div className="h-8/12 w-full">{
targetText
}</div>
<div className="ipa w-full h-2/12 overflow-auto text-gray-600">
{targetIPA}
</div>
<div className="h-2/12 w-full flex justify-end items-center">
<IconClick onClick={async () => {
if (targetText.length !== 0)
await navigator.clipboard.writeText(targetText);
}} src={IMAGES.copy_all} alt="copy"></IconClick>
<IconClick onClick={readTarget} src={IMAGES.play_arrow} alt="play"></IconClick>
</div>
</div>
<div className="option2 w-full flex gap-1 items-center flex-wrap">
<span>translate into</span>
<Button onClick={() => { setTargetLang('English') }} label="English" selected={targetLang === 'English'}></Button>
<Button onClick={() => { setTargetLang('Italian') }} label="Italian" selected={targetLang === 'Italian'}></Button>
<Button onClick={() => { setTargetLang('Japanese') }} label="Japanese" selected={targetLang === 'Japanese'}></Button>
<Button onClick={inputLanguage} label={'Other' + (tl.includes(targetLang) ? '' : ': ' + targetLang)} selected={!(tl.includes(targetLang))}></Button>
</div>
</div>
</div>
<div className="button-area w-screen flex justify-center items-center">
<button onClick={translate} className={`text-xl font-extrabold border rounded-4xl p-3 border-gray-200 h-16 ${translating ? 'bg-gray-200' : 'bg-white hover:bg-gray-200 hover:cursor-pointer'}`}>
{translating ? 'translating...' : 'translate'}
</button>
</div>
</>
);
}

View File

@@ -0,0 +1,46 @@
'use client';
import { BOARD_WIDTH, TEXT_WIDTH, BOARD_HEIGHT, TEXT_SIZE } from "@/constants";
import { Word } from "@/interfaces";
import { Dispatch, SetStateAction, useEffect } from "react";
export default function WordBoard(
{ words, setWords, selectWord }: {
words: [
{
word: string,
x: number,
y: number
}
],
setWords: Dispatch<SetStateAction<Word[]>>,
selectWord: (word: string) => void
}
) {
function DraggableWord({ word }: { word: Word }) {
return (<span
style={{
left: `${Math.floor(word.x * (BOARD_WIDTH - TEXT_WIDTH * word.word.length))}px`,
top: `${Math.floor(word.y * (BOARD_HEIGHT - TEXT_SIZE))}px`,
fontSize: `${TEXT_SIZE}px`
}}
className="select-none cursor-pointer absolute code-block border-amber-100 border-1"
// onClick={inspect(word.word)}>{word.word}</span>))
onClick={() => { selectWord(word.word); }}>{word.word}</span>);
}
return (
<div style={{
width: `${BOARD_WIDTH}px`,
height: `${BOARD_HEIGHT}px`
}} className="relative rounded bg-white">
{words.map(
(v: {
word: string,
x: number,
y: number
}, i: number) => {
return (<DraggableWord word={v} key={i}></DraggableWord>)
})}
</div>
)
}

159
src/app/word-board/page.tsx Normal file
View File

@@ -0,0 +1,159 @@
'use client';
import WordBoard from "@/app/word-board/WordBoard";
import Button from "../../components/Button";
import { KeyboardEvent, useRef, useState } from "react";
import { Word } from "@/interfaces";
import { BOARD_WIDTH, TEXT_WIDTH, BOARD_HEIGHT, TEXT_SIZE } from "@/constants";
import { inspect } from "@/utils";
export default function Home() {
const inputRef = useRef<HTMLInputElement>(null);
const inputFileRef = useRef<HTMLInputElement>(null);
const initialWords =
[
// 'apple',
// 'banana',
// 'cannon',
// 'desktop',
// 'kernel',
// 'system',
// 'programming',
// 'owe'
] as Array<string>;
const [words, setWords] = useState(
initialWords.map((v: string) => ({
'word': v,
'x': Math.random(),
'y': Math.random()
}))
);
const generateNewWord = (word: string) => {
const isOK = (w: Word) => {
if (words.length === 0) return true;
const tf = (ww: Word) => ({
word: ww.word,
x: Math.floor(ww.x * (BOARD_WIDTH - TEXT_WIDTH * ww.word.length)),
y: Math.floor(ww.y * (BOARD_HEIGHT - TEXT_SIZE))
} as Word);
const tfd_words = words.map(tf);
const tfd_w = tf(w);
for (const www of tfd_words) {
const p1 = {
x: (www.x + www.x + TEXT_WIDTH * www.word.length) / 2,
y: (www.y + www.y + TEXT_SIZE) / 2
}
const p2 = {
x: (tfd_w.x + tfd_w.x + TEXT_WIDTH * tfd_w.word.length) / 2,
y: (tfd_w.y + tfd_w.y + TEXT_SIZE) / 2
}
if (
Math.abs(p1.x - p2.x) < (TEXT_WIDTH * (www.word.length + tfd_w.word.length)) / 2 &&
Math.abs(p1.y - p2.y) < TEXT_SIZE
) {
return false;
}
}
return true;
}
let new_word;
let count = 0;
do {
new_word = {
word: word,
x: Math.random(),
y: Math.random()
};
if (++count > 1000) return null;
} while (!isOK(new_word));
return new_word as Word;
}
const insertWord = () => {
if (!inputRef.current) return;
const word = inputRef.current.value.trim();
if (word === '') return;
const new_word = generateNewWord(word);
if (!new_word) return;
setWords([...words, new_word]);
inputRef.current.value = '';
}
const deleteWord = () => {
if (!inputRef.current) return;
const word = inputRef.current.value.trim();
if (word === '') return;
setWords(words.filter((v) => v.word !== word));
inputRef.current.value = '';
};
const importWords = () => {
inputFileRef.current?.click();
}
const exportWords = () => {
const blob = new Blob([JSON.stringify(words)], {
type: 'application/json'
});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${Date.now()}.json`;
a.style.display = 'none';
a.click();
URL.revokeObjectURL(url);
}
const handleFileChange = () => {
const files = inputFileRef.current?.files;
if (files && files.length > 0) {
const reader = new FileReader();
reader.onload = () => {
if (reader.result && typeof reader.result === 'string')
setWords(JSON.parse(reader.result) as [Word]);
}
reader.readAsText(files[0]);
}
}
const deleteAll = () => {
setWords([] as Array<Word>);
}
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
// e.preventDefault();
if (e.key === 'Enter') {
insertWord();
}
}
const selectWord = (word: string) => {
if (!inputRef.current) return;
inputRef.current.value = word;
}
const searchWord = () => {
if (!inputRef.current) return;
const word = inputRef.current.value.trim();
if (word === '') return;
inspect(word)();
inputRef.current.value = '';
}
// const readWordAloud = () => {
// playFromUrl('https://fanyi.baidu.com/gettts?lan=uk&text=disclose&spd=3')
// return;
// if (!inputRef.current) return;
// const word = inputRef.current.value.trim();
// if (word === '') return;
// inspect(word)();
// inputRef.current.value = '';
// }
return (
<div className="flex w-screen h-screen justify-center items-center">
<div onKeyDown={handleKeyDown} className="p-5 bg-gray-200 rounded shadow-2xl">
<WordBoard selectWord={selectWord} words={words as [Word]} setWords={setWords} />
<div className="flex justify-center rounded mt-3 gap-1">
<input ref={inputRef} placeholder="word to operate" type="text" className="focus:outline-none border-b-2 border-black" />
<Button label="插入" onClick={insertWord}></Button>
<Button label="删除" onClick={deleteWord}></Button>
<Button label="搜索" onClick={searchWord}></Button>
<Button label="导入" onClick={importWords}></Button>
<Button label="导出" onClick={exportWords}></Button>
<Button label="删光" onClick={deleteAll}></Button>
{/* <Button label="朗读" onClick={readWordAloud}></Button> */}
</div>
<input type="file" ref={inputFileRef} className="hidden" accept="application/json" onChange={handleFileChange}></input>
</div>
</div>
);
}

21
src/components/Button.tsx Normal file
View File

@@ -0,0 +1,21 @@
export default function Button({
label,
onClick,
className = '',
selected = false
}: {
label:
string,
onClick?: () => void,
className?: string,
selected?: boolean
}) {
return (
<button
onClick={onClick}
className={`px-2 py-1 rounded shadow-2xs font-bold hover:bg-gray-300 hover:cursor-pointer ${selected ? 'bg-gray-300' : "bg-white"} ${className}`}
>
{label}
</button>
);
}

View File

@@ -0,0 +1,23 @@
import Image from "next/image";
interface IconClickProps {
src: string;
alt: string;
onClick?: () => void;
className?: string;
size?: number
}
export default function IconClick(
{ src, alt, onClick = () => { }, className = '', size = 32 }: IconClickProps) {
return (<>
<div onClick={onClick} className={`hover:cursor-pointer hover:bg-gray-200 rounded-3xl w-[${size}px] h-[${size}px] flex justify-center items-center ${className}`}>
<Image
src={src}
width={size - 5}
height={size - 5}
alt={alt}
></Image>
</div>
</>);
}

20
src/config/images.ts Normal file
View File

@@ -0,0 +1,20 @@
const IMAGES = {
speed_1_5x: '/images/speed_1_5x_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
speed_1_2_x: '/images/speed_1_2x_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
speed_0_7x: '/images/speed_0_7x_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
pause: '/images/pause_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
speed_0_5x: '/images/speed_0_5x_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
copy_all: '/images/copy_all_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
autoplay: '/images/autoplay_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
autopause: '/images/autopause_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
speed_1x: '/images/1x_mobiledata_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
play_arrow: '/images/play_arrow_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
close: '/images/close_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
refresh: '/images/refresh_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
more_horiz: '/images/more_horiz_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
save: '/images/save_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
delete: '/images/delete_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
speed: '/images/speed_24dp_1F1F1F_FILL0_wght400_GRAD0_opsz24.svg',
}
export default IMAGES;

4
src/constants.ts Normal file
View File

@@ -0,0 +1,4 @@
export const BOARD_WIDTH = 800;
export const BOARD_HEIGHT = 500;
export const TEXT_SIZE = 30;
export const TEXT_WIDTH = TEXT_SIZE * 0.6;

View File

@@ -0,0 +1,34 @@
import { useRef, useEffect } from "react";
export function useAudioPlayer() {
const audioRef = useRef<HTMLAudioElement | null>(null);
useEffect(() => {
audioRef.current = new Audio();
return () => {
audioRef.current!.pause();
audioRef.current = null;
};
}, []);
const playAudio = async (audioUrl: string) => {
audioRef.current!.src = audioUrl;
try {
await audioRef.current!.play();
} catch (e) {
return e;
}
};
const pauseAudio = () => {
audioRef.current!.pause();
};
const stopAudio = () => {
audioRef.current!.pause();
audioRef.current!.currentTime = 0;
};
return {
playAudio,
pauseAudio,
stopAudio,
audioRef
};
}

20
src/interfaces.ts Normal file
View File

@@ -0,0 +1,20 @@
import z from "zod";
export interface Word {
word: string;
x: number;
y: number;
}export interface Letter {
letter: string;
letter_name_ipa: string;
letter_sound_ipa: string;
roman_letter?: string;
}
export type SupportedAlphabets = 'japanese' | 'english' | 'esperanto' | 'uyghur';
export const TextSpeakerItemSchema = z.object({
text: z.string(),
ipa: z.string().optional(),
locale: z.string()
});
export const TextSpeakerArraySchema = z.array(TextSpeakerItemSchema);

77
src/utils.ts Normal file
View File

@@ -0,0 +1,77 @@
import { EdgeTTS, ProsodyOptions } from "edge-tts-universal/browser";
import { TextSpeakerArraySchema } from "./interfaces";
import z from "zod";
export function inspect(word: string) {
const goto = (url: string) => {
window.open(url, '_blank');
}
return () => {
word = word.toLowerCase();
goto(`https://www.youdao.com/result?word=${word}&lang=en`);
}
}
export function urlGoto(url: string) {
window.open(url, '_blank');
}
const API_KEY = process.env.ZHIPU_API_KEY;
export async function callZhipuAPI(messages: { role: string; content: string; }[], model = 'glm-4.5-flash') {
const url = 'https://open.bigmodel.cn/api/paas/v4/chat/completions';
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: model,
messages: messages,
temperature: 0.2,
thinking: {
type: 'disabled'
}
})
});
if (!response.ok) {
throw new Error(`API 调用失败: ${response.status}`);
}
return await response.json();
}
export async function getTTSAudioUrl(text: string, short_name: string, options: ProsodyOptions | undefined = undefined) {
const tts = new EdgeTTS(text, short_name, options);
try {
const result = await tts.synthesize();
return URL.createObjectURL(result.audio);
} catch (e) {
throw e;
}
}
export const getTextSpeakerData = () => {
try {
const item = localStorage.getItem('text-speaker');
if (!item) return [];
const rawData = JSON.parse(item);
const result = TextSpeakerArraySchema.safeParse(rawData);
if (result.success) {
return result.data;
} else {
console.error('Invalid data structure in localStorage:', result.error);
return [];
}
} catch (e) {
console.error('Failed to parse text-speaker data:', e);
return [];
}
};
export const setTextSpeakerData = (data: z.infer<typeof TextSpeakerArraySchema>) => {
if (!localStorage) return;
localStorage.setItem('text-speaker', JSON.stringify(data));
};

27
tsconfig.json Normal file
View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}