Building espeak-ng and pcaudiolib on mingw64

News and discussion of the PC port of Oolite.

Moderators: another_commander, winston

User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

I built espeak-ng on mingw64 with gcc. It only built successfully using the very recent and not yet documented cmake setup not the documented and eventually to be deprecated configure/make setup. I built it like this:

Code: Select all

mkdir build
cd build
cmake  -GNinja -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -S .. -B . -DBUILD_SHARED_LIBS=YES -DHAVE_PTHREAD=yes
cmake --build .
cmake --install . --prefix /mingw64
When I ran Oolite, it failed, but I later realised it could not find the espeak-ng data. I hacked it for testing purposes once I discovered it was trying to look in C:\Program Files (x86)\espeak-ng\share\espeak-ng-data by running:

Code: Select all

cmake --install .
which installs into the default location of C:\Program Files (x86)\espeak-ng. However, having looked at the code, I suspect that the files in espeak-ng-data could simply be put in oolite.app\Resources\espeak-data and if that doesn't work then the code looks at an environment variable ESPEAK_DATA_PATH which can be set appropriately.

I ran Oolite and it appeared to work, offering the choice of many different voices eg. Afrikaans. However, no words were actually spoken. I checked and then realised it needs a dependency pcaudiolib for audio output.

I tried to build pcaudiolib. The xaudio2 build didn't seem to work probably because it assumes the Visual Studio compiler. There's also a ticket about Windows support. I needed a sound server so I tried pulseaudio support. MSYS2 has a pulseaudio mingw64 package which installed ok. With some modifications, I could get pcaudiolib to build and use it:

Code: Select all

./autogen.sh
./configure --prefix=/mingw64
sed -i.bak -e "s/\(allow_undefined=\)yes/\1no/" libtool
make LIBTOOLFLAGS=-v -j16
However, when I tried to start pulseaudio itself, I got an error so the MSYS2 pulseaudio package seems to be broken. It gives output like this when running the pulseaudio command:

Code: Select all

W: [(null)] ../pulseaudio-17.0/src/pulsecore/core-util.c: Secure directory creation not supported on this platform.
E: [(null)] ../pulseaudio-17.0/src/modules/module-protocol-stub.c: Failed to remove stale UNIX socket 'C:\msys64\home\mcara\.config\pulse\Holly-runtime\native': No such file or directory
E: [(null)] ../pulseaudio-17.0/src/pulsecore/module.c: Failed to load module "module-native-protocol-unix" (argument: ""): initialization failed.
W: [(null)] ../pulseaudio-17.0/src/pulsecore/cli-command.c: stat('C:\msys64\mingw64\etc\pulse\/default.pa.d'): No such file or directory
W: [(null)] ../pulseaudio-17.0/src/pulsecore/core-util.c: Secure directory creation not supported on this platform.
I also tried a Pulseaudio build outside of MSYS2: https://pgaskin.net/pulseaudio-win32/ but that didn't seem to be recognised by the espeak-ng command line tool.
Last edited by mcarans on Mon Sep 15, 2025 6:17 am, edited 3 times in total.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

I think what's needed is to fix up or reimplement xaudio2 support in pcaudiolib to work with gcc.

Alternative is to implement OpenAl support which could be used by both mingw64 and Linux. Although Linux already has a pulseaudio backend, perhaps OpenAl would be more efficient?

This is a standalone C and C++ coding task not requiring building Oolite and it can be tested without running the game eg. if it is working, you will hear "hello", if you run:

Code: Select all

espeak-ng "hello"
pcaudiolib is just a simple C wrapper around various sound servers so the task sounds fairly straightforward for someone who is familiar with Windows coding (or OpenAl).

If it works, it will not only mean that Oolite can use espeak-ng, but also that espeak-ng can be made available in mingw64 environments for others to use so a double win (and possibly opening up other things that use pcaudiolib to work on mingw64). Is there anyone in the Oolite community experienced in this area? Otherwise, I'll have a crack at it.
Last edited by mcarans on Mon Sep 15, 2025 4:23 am, edited 2 times in total.
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 781
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: Building espeak-ng and pcaudiolib on mingw64

Post by Lone_Wolf »

Alternative is to implement OpenAl support which could be used by both mingw64 and Linux. Although Linux already has a pulseaudio backend, perhaps OpenAl would be more efficient?
Are you sure OpenAI TTS API would be more efficient/usable on linux ?

The only OpenAI packages I see in archlinux official repos are

Code: Select all

python-openai - Python client library for the OpenAI API
python-openai-whisper - Robust speech recognition via large-scale weak supervision
python-tiktoken - A fast BPE tokeniser for use with OpenAI's models
The first seems relevant and is used by exactly 2 applications : chatblade & feeluown .
Also python is not exactly known for high performance .
OS : Arch Linux 64-bit - rolling release

From: The Netherlands, Europe

OXPs : My user page (needs updating)

Retired, occasionally active
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

Lone_Wolf wrote: Sun Sep 14, 2025 10:06 am
Alternative is to implement OpenAl support which could be used by both mingw64 and Linux. Although Linux already has a pulseaudio backend, perhaps OpenAl would be more efficient?
Are you sure OpenAI TTS API would be more efficient/usable on linux ?
It seems that lowercase L (l) and uppercase i (I) look the same :-) I was referring to the OpenAL cross platform 3d audio library. This library is already needed by Oolite eg.

Code: Select all

-lopenal32.dll
in Windows and

Code: Select all

-lopenal
in Linux in the GNUmakefile.

Another cross platform alternative is portaudio which I believe the original espeak used as a backend. There's a fairly recent discussion that mentions them both here:
"As the creator of Slappy - 3d sound api for nim - mentioned above, I had the same problem. I looked for something better and couldn't find it, so I returned to OpenAL. With OpenAL, there are many implementations and bindings. It's been around for so long, and I've used it for years with success."

"portaudio is an old system that is often used by older apps that you could try if you don't need realtime. I found it reasonably well done."

I lean towards OpenAL over portaudio or XAudio2 because of the advantages mentioned above as well as the cross platform support which has the personal advantage that I can get back to developing on Linux my main operating system but I will first have a quick look at the existing Windows XAudio2 code in pcaudiolib if noone else steps forward in case it is easy to fix.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

I managed to get the existing Windows xaudio2 code to work with some small changes. espeak-ng "hello" produced the desired hello result. It worked in Oolte as well.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 7141
Joined: Wed Feb 28, 2007 7:54 am

Re: Building espeak-ng and pcaudiolib on mingw64

Post by another_commander »

Crashed right away for me with this message in stderr.txt:
stderr.txt wrote:
Error processing file 'C:/Program Files (x86)/espeak-ng/share/espeak-ng-data\phontab': No such file or directory.
The default data folders are set incorrectly.
Commander_X
---- E L I T E ----
---- E L I T E ----
Posts: 736
Joined: Sat Aug 09, 2014 4:16 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by Commander_X »

The only drawback I noticed is that the voice seems to block, that is, the call doesn't seem to be done asynchronously. E.g. when I try change the view forward to starboard when a message is spoken, it "hangs" until the message is finished.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 7141
Joined: Wed Feb 28, 2007 7:54 am

Re: Building espeak-ng and pcaudiolib on mingw64

Post by another_commander »

Did you have to copy the espeak data to ProgramFiles or did it work out of the box for you?

Also, this absolutely needs to be asynchronous. Blocking to play a message is not acceptable for realtime applications
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

another_commander wrote: Tue Sep 16, 2025 3:21 pm
Did you have to copy the espeak data to ProgramFiles or did it work out of the box for you?

Also, this absolutely needs to be asynchronous. Blocking to play a message is not acceptable for realtime applications
The espeak-ng data files will ultimately need to be copied over the existing data files I think. Alternatively an environment variable can be set.

That's strange about the asynchronous issue. I recall that espeak-ng cmake returned that it was using async and I had changed xaudio2 coinitialize to multithreaded.
Last edited by mcarans on Wed Sep 17, 2025 2:11 am, edited 2 times in total.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 7141
Joined: Wed Feb 28, 2007 7:54 am

Re: Building espeak-ng and pcaudiolib on mingw64

Post by another_commander »

Can you please upload the espeak-ng-data directory somewhere? Can't run the game without it.
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

another_commander wrote: Tue Sep 16, 2025 6:57 pm
Can you please upload the espeak-ng-data directory somewhere? Can't run the game without it.
Here you go: https://www.filemail.com/d/ppplouqkifyugsl
Commander_X
---- E L I T E ----
---- E L I T E ----
Posts: 736
Joined: Sat Aug 09, 2014 4:16 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by Commander_X »

another_commander wrote: Tue Sep 16, 2025 3:21 pm
Did you have to copy the espeak data to ProgramFiles or did it work out of the box for you?
[...]
Yes, I actually had a espeak-ng-data folder made while I compiled my own attempt at building espeak-ng. I also started

Code: Select all

.\oolite -hdr
in the same command prompt where I previously ran

Code: Select all

set ESPEAK_DATA_PATH=<absolute_path_to_oolite.app>\Resources
User avatar
mcarans
---- E L I T E ----
---- E L I T E ----
Posts: 662
Joined: Sun Jun 20, 2010 6:00 pm

Re: Building espeak-ng and pcaudiolib on mingw64

Post by mcarans »

another_commander wrote: Tue Sep 16, 2025 3:21 pm
Did you have to copy the espeak data to ProgramFiles or did it work out of the box for you?

Also, this absolutely needs to be asynchronous. Blocking to play a message is not acceptable for realtime applications
Do you experience the same issue of blocking when speech plays in Oolite?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 7141
Joined: Wed Feb 28, 2007 7:54 am

Re: Building espeak-ng and pcaudiolib on mingw64

Post by another_commander »

mcarans wrote: Tue Sep 16, 2025 9:05 pm
Do you experience the same issue of blocking when speech plays in Oolite?
In the standard distribution you mean? No, absolutely not. I went to great lengths to ensure asynchronous speech when I built the espeak dll we currently distribute. Had to turn on a lot of Linux-only stuff to achieve that.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 7141
Joined: Wed Feb 28, 2007 7:54 am

Re: Building espeak-ng and pcaudiolib on mingw64

Post by another_commander »

The external libs source modifications document in the Doc folder of Oolite's tree contains instructions for building espeak with async playback support. Have you had a chance to look at it?
Post Reply