Introduction#
For those who don't want to tinker, deploying through Vercel may be more convenient. See iFreeTime Audiobook Microsoft AI Voice TTS Vercel Deployment Tutorial | Yunfi's Blog for details.
- Docker implementation
- Project address: yy4382/ms-ra-forwarder-for-ifreetime
- Modified from wxxxcxx/ms-ra-forwarder: Free Online Text-to-Speech API (github.com), don't forget to give the developer a star
- Special thanks to @justnsms for writing the code. Without his help, this convenient method would not have been possible.
- If you encounter any problems during the configuration process, you can email me (email address is in the blog sidebar)
Prerequisites#
- A machine capable of running Docker
- Docker installed
Refer to the "Installing Docker" section of this article: #Installing Docker | Yunfi's Blog
Installing the Server-side#
Installation#
# Create a folder with any name
mkdir ifreetime_tts && cd ifreetime_tts
# Download the file
wget https://gist.github.com/yy4382/d0c2a5e2c19323f4aa651f99317fd53e/raw/docker-compose.yml
# Start the container
docker compose up -d
# Done! Verify if it is successful using the method described below, and then configure it in iFreeTime.
If you want to set a token, follow the instructions in the yaml file.
Configuring iFreeTime on iOS#
Refer to the Vercel Deployment Tutorial | iFreeTime Configuration Section , the only difference is the address, which should be
https://ip:3000/api/aiyue
If you have any issues, please leave a comment.
Appendix#
This is the initial version I made, which is quite complicated and is for reference only.
- Two services are required: one is the TTS text-to-speech service, which is only needed for Android Reading 3.0; the other is to convert the first service into a format that iFreeTime can use.
- Addresses of the two projects: wxxxcxx/ms-ra-forwarder: Free Online Text-to-Speech API (github.com) , iranee/ifreetime: Self-hosted iOS iFreeTime TTS Service (github.com). Don't forget to give both developers a star.
It may be a bit troublesome and requires basic knowledge of Docker, but it can help you understand how everything works. It is placed at the end of the article.
ms-ra-forwarder#
- GitHub address: wxxxcxx/ms-ra-forwarder: Free Online Text-to-Speech API (github.com)
- The project itself provides a
docker-compose.yml
file, just use it directly. - Open
http://your-ip:3000
to see if the page exists.
You can also use Vercel, but it only provides 100GB of free traffic per month, so be careful if you listen a lot or have other services running.
- Because Microsoft has closed the trial of Azure, we can only use the ra (edge's loud reading) interface.
ifreetime#
-
Project address: iranee/ifreetime: Self-hosted iOS iFreeTime TTS Service (github.com)
-
If you already have a server running a website that supports PHP, just change the IP in the
ra.php
file to the one you used in the first step, and then put it in the website. -
If not, you need to create a Docker container to run the PHP file (Warning: I have never written PHP before, the Dockerfile syntax was provided by ChatGPT, so I can't guarantee it's optimal, but it should work, as I have succeeded).
-
Create a new folder, let's call it ifreetime (or any other name).
-
Enter the folder and create another folder called src, and put the ra.php file from the project into it (or clone the entire project directly).
-
Modify ra.php, change
http://127.0.0.1:3000/api/ra
to the IP and port you generated in the first step- For servers, the easiest way is to use the public IP address + port, for Synology NAS, the simplest way is to use the LAN IP address + port.
- Tested alternative solutions:
- After setting up domain name resolution and reverse proxy on a cloud server, use a format like
https://tts.example.com/api/ra
(usinghttps://tts.example.com
to access ms-ra-forwarder). - Use the IP of the local Docker, usually 172.17.0.1, so it should be
http://172.17.0.1:3000/api/ra
.
- After setting up domain name resolution and reverse proxy on a cloud server, use a format like
- Solutions that don't work: Cannot use 127.0.0.1 because it is inside the container.
- Solutions that may cause problems: Domain name + port format, such as
https://www.example.com:3000/api/ra
, especially for NAS, because port 80/443 cannot be used, so an additional port must be added. Someone failed with this method, but it is not certain if it is due to this issue. If someone succeeds with this method, please email me (email address is written on the blog).
-
Go back to the ifreetime folder and create a file called
Dockerfile
with the following content:# Set the base image FROM php:7.3 # Copy the local code to the /var/www/html directory in the container COPY src/ /var/www/html/ # Set the working directory inside the container WORKDIR /var/www/html # Expose port 8000 of the container EXPOSE 8000 # Start the PHP server CMD ["php", "-S", "0.0.0.0:8000"]
-
Build and run: In the ifreetime directory, enter the following commands one by one
docker build -t ifreetime . docker run -d -p 12222:8000 ifreetime
-
With this method, you need to replace all instances of 3000 with 12222 in the iFreeTime configuration (including during testing). Also, replace /api/aiyue with /ra.php.
-
Open the iFreeTime app on your phone, go to Audiobook Configuration -> Custom Voice Library
Create -> Advanced Custom Voice SynthesisName: Any name
Number of Characters: Recommended 200
Request Method: GET
Address: ra.php network address, if you installed it using the method above, it is
http://your-ip:12222/ra.php
Parameters -> Add -> Enter Request Parameter: voiceName, content is the desired voice (refer to here), for example, zh-CN-XiaoxiaoNeural
Parameters -> Add -> Enter Request Parameter: text, content is %@
Parsing Field -> Add -> Enter Parsing Field and Rule: playData, content is ResponseData
Test Pronunciation, if it is correct, it's okay.