Skip to content

Commit

Permalink
Add support for "OneCore" voices
Browse files Browse the repository at this point in the history
  • Loading branch information
bertfrees committed Dec 13, 2022
2 parents 6b36f31 + 02c91a3 commit 9f0cfc5
Show file tree
Hide file tree
Showing 53 changed files with 2,522 additions and 868 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
<artifactId>tts-adapter-sapinative</artifactId>
<version>3.0.6</version>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
Expand Down
17 changes: 15 additions & 2 deletions tts/tts-adapters/tts-adapter-sapinative/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
build\
.vs\
# Visual Studio
*.vcxproj.*
/build/
/packages/
/src/main/jni/onecorenative/Generated Files
/src/main/jni/onecorenative/Release
/src/main/jni/onecorenative/x64
/src/main/resources/x64/*
/src/main/resources/x86/*

# DLLs are committed
!/src/main/resources/x64/sapinative.dll
!/src/main/resources/x64/onecorenative.dll
!/src/main/resources/x86/sapinative.dll
!/src/main/resources/x86/onecorenative.dll
49 changes: 26 additions & 23 deletions tts/tts-adapters/tts-adapter-sapinative/README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
# Daisy Pipeline 2 TTS Adapter - Microsoft SAPI and OneCore voices

This adapter provides Text-to-speech capabilities to the DAISY pipeline 2 using Microsoft SAPI and (under developement) OneCore voices on Windows hosts.
This adapter provides Text-to-speech capabilities to the DAISY pipeline 2 using Microsoft SAPI and (under development) OneCore voices on Windows hosts.

## Building the adapter

This adapter is made of Windows DLLs that use the Java Native Interface to be exposed to the pipeline, and a java-side connector between those DLLs and the pipeline framework.

Stable release versions of the dlls are provided with the adapter, so the project can be build "as-is" using maven with the command `maven clean install`.
Stable release versions of the DLLs are provided with the adapter, so the project can be built "as-is" using maven with the command `maven clean install`.

If you want or need to update the dlls, you can rebuild the dlls before building the adapter following the instructions in the next section.
If you want or need to update the DLLs, you can rebuild the DLLs before building the adapter by following the instructions in the next section.

## Rebuilding the "sapinative" dlls
## Rebuilding the "Sapinative" dlls

To build the adapter's dlls, we recommend to install [Visual studio 2019 or newer](https://visualstudio.microsoft.com/fr/vs/community/) (VS2019 community is currently used), with development tools for C++/Desktop application, including windows 10 SDK
(you might need to check if you have those option installed under the menu "Tools/Get tools and functionnalities")
To build the adapter's DLLs, we recommend installing [Visual Studio Community](https://visualstudio.microsoft.com/fr/vs/community/), with the following tools and functionalities also installed:
- Development tools for C++/Desktop applications,
- Windows 10 SDK.
The project DLLs are currently built using Visual Studio Community 2022, version 17.3.3.
If you already have Visual Studio Community or Enterprise edition installed, please check that those functionalities are already part of your installation, by going under the `Tools/Get tools and functionalities` section of the application menu.

Or if you don't want to use visual studio (untested) and want to build from the command line, you will need:
If you don't want to use visual studio and want to build from the command line, you will need:
- the [MSBuild toolset](https://visualstudio.microsoft.com/fr/downloads/?q=build+tools)
- When requested, select the "desktop development with C++" workload
- the [Windows 10 SDK (tested with 10.0.19041)](https://go.microsoft.com/fwlink/?linkid=2120843)
More informations are provided by Microsoft in [their documentation](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170) for buliding such project from the command line.
More information are provided by Microsoft in [their documentation](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170) to build projects and solutions from the command line.

The following environment variable also need to be set for the code to build
The following environment variables also need to be set for the code to build
- JAVA_HOME needs to point to a [java 11 JDK](https://adoptium.net/?variant=openjdk11&jvmVariant=hotspot)
- If you installed MSBuild, add its Bin folder to your PATH environment variable

### With visual studio
### With Visual Studio Community

Using visual studio 2019, the projects and solution should be ready for build.
In Visual Studio, first select the "Release" configuration and then build the DLLs for x86 and x64 platform:
Using Visual Studio Community, the solution should be ready for build.
In Visual Studio, select the "Release" configuration and then build the DLLs for "x86" and "x64" platforms by respectively:
- Select the "x86" platform and launch the build with the menu action "Build/Build the solution"
- Select the "x64" platform and launch the build with the menu action "Build/Build the solution"

If the build was successful, this should have updated the DLLs under `src/main/resources/(x86|x64)/sapinative.dll`
If the build was successful, the DLLs under `src/main/resources/(x86|x64)/` will be updated.

Alternatively, you can also open the developer command line with the menu "Tools/Command line/Developer command line" and launch the following commands:
Alternatively, you can also open the developer command line with the menu `Tools/Command line/Developer command line` and launch the following commands:
```
msbuild sapinative.sln -p:Configuration=Release -p:Platform="x86"
msbuild sapinative.sln -p:Configuration=Release -p:Platform="x64"
```

### With MSBuild (with or without visual studio)
### With MSBuild (with or without Visual Studio)

Build with MSBuild separate installation has not yet be tested, so your mileage may vary.

From a command line interpreter positionned at the root of the repository, you should be able to launch the following commands to update the dlls (with MSBuild accessible from your PATH):
Build with MSBuild separate installation has not yet been fully tested, so your mileage may vary.

With the `msbuild.exe` parent directory registered in your PATH environment variable, open a command line interpreter and position it at the root of the repository.
Then launch the following commands to update the DLLs:
```
msbuild.exe sapinative.sln -p:Configuration=Release -p:Platform="x86"
msbuild.exe sapinative.sln -p:Configuration=Release -p:Platform="x64"
```

### Activating the dll unit tests
### Activating the DLL unit tests

By default, the dll unit tests are deactivated to allow the build to proceed of non-windows build servers.
By default, the DLL unit tests are deactivated to allow the build to proceed on non-windows build servers.
If you want to reactivate the tests, open the test/java/ignore file and uncomment the first line

## Possible issues or warnings

### Exception raised after unit tests are passed

On some occasion when building the maven project with SAPINative tests activated, you might encountered an jni exception that does block the unit tests.
The circumstances that make the unit tests raising this exception when unloading the DLL has not yet been identified, the exception not being raised consistently in builds attempts.
From our best knowledge, this issue has not yet impacted any production scenario as it might occure when the pipeline is exiting and disposing the sapinative bridge library.
On some occasions when building the maven project with SAPINative tests activated, you might encounter a jni exception that blocks the unit tests.
The circumstances that make the unit tests raise this exception when unloading the DLLs have not yet been identified, as the exception is not raised consistently in build attempts.
To our best knowledge, this issue has not yet impacted any production scenario as it might occur when the pipeline is exiting and disposing of the "Sapinative" bridge library.
98 changes: 42 additions & 56 deletions tts/tts-adapters/tts-adapter-sapinative/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../../../parent</relativePath>
</parent>

<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<artifactId>tts-adapter-sapinative</artifactId>
<packaging>bundle</packaging>

Expand Down Expand Up @@ -45,7 +45,7 @@

<properties>
<expose-services>
org.daisy.pipeline.tts.sapinative.impl.SAPIservice
org.daisy.pipeline.tts.sapi.impl.SAPIService
</expose-services>
</properties>

Expand All @@ -64,82 +64,68 @@
</instructions>
</configuration>
</plugin>

<!-- note: Run mvn compile native:javah to generate again the C++ headers from -->
<!-- the Java class. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>none</phase>
<id>default-cli</id>
<goals>
<goal>javah</goal>
</goals>
<configuration>
<javahOS>windows</javahOS>
<javahOutputDirectory>../../native-libs/sapi-nar/src/main/jni</javahOutputDirectory>
<javahClassNames>
<javahClassName>org.daisy.pipeline.tts.sapinative.SAPILib</javahClassName>
</javahClassNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<!-- Extract the libraries from the NAR package -->
<profile>
<id>generate-dll</id>
<!-- Run mvn -Pgenerate-sapinative-headers compile native:javah to generate again the C++ headers from the Java class -->
<id>generate-sapinative-headers</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<phase>none</phase>
<id>default-cli</id>
<goals>
<goal>unpack</goal>
<goal>javah</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.daisy.pipeline.bindings</groupId>
<artifactId>sapi-nar</artifactId>
<version>1.0.0</version>
<classifier>x64-Windows-msvc-jni</classifier>
<type>nar</type>
</artifactItem>
<artifactItem>
<groupId>org.daisy.pipeline.bindings</groupId>
<artifactId>sapi-nar</artifactId>
<version>1.0.0</version>
<classifier>x86-Windows-msvc-jni</classifier>
<type>nar</type>
</artifactItem>
</artifactItems>
<javahOS>windows</javahOS>
<javahOutputDirectory>src/main/jni/sapinative</javahOutputDirectory>
<javahClassNames>
<javahClassName>org.daisy.pipeline.tts.onecore.SAPI</javahClassName>
</javahClassNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Run mvn -Pgenerate-onecorenative-headers compile native:javah to generate again the C++ headers from the Java class -->
<id>generate-onecorenative-headers</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<phase>none</phase>
<id>default-cli</id>
<goals>
<goal>run</goal>
<goal>javah</goal>
</goals>
<configuration>
<tasks>
<copy file="target/dependency/lib/x64-Windows-msvc/jni/sapi-nar.dll" tofile="src/main/resources/x64/sapinative.dll"/>
<copy file="target/dependency/lib/x86-Windows-msvc/jni/sapi-nar.dll" tofile="src/main/resources/x86/sapinative.dll"/>
</tasks>
<javahOS>windows</javahOS>
<javahOutputDirectory>src/main/jni/onecore</javahOutputDirectory>
<javahClassNames>
<javahClassName>org.daisy.pipeline.tts.onecore.Onecore</javahClassName>
</javahClassNames>
</configuration>
</execution>
</executions>
Expand All @@ -149,4 +135,4 @@
</profile>
</profiles>

</project>
</project>
29 changes: 26 additions & 3 deletions tts/tts-adapters/tts-adapter-sapinative/sapinative.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32106.194
# Visual Studio Version 17
VisualStudioVersion = 17.1.32319.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sapinative", "sapinative.vcxproj", "{161FEC8C-CF12-4F78-A869-A26A98EB2640}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sapinative", "src\main\jni\sapinative\sapinative.vcxproj", "{161FEC8C-CF12-4F78-A869-A26A98EB2640}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{926E1B1E-02B8-42C2-818B-DA7A30001C5F}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "onecorenative", "src\main\jni\onecorenative\onecorenative.vcxproj", "{88754889-B2B2-44BE-9BE9-4DD21808206E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -29,6 +36,22 @@ Global
{161FEC8C-CF12-4F78-A869-A26A98EB2640}.Release|x64.Build.0 = Release|x64
{161FEC8C-CF12-4F78-A869-A26A98EB2640}.Release|x86.ActiveCfg = Release|Win32
{161FEC8C-CF12-4F78-A869-A26A98EB2640}.Release|x86.Build.0 = Release|Win32
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|ARM.ActiveCfg = Debug|ARM
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|ARM.Build.0 = Debug|ARM
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|ARM64.ActiveCfg = Debug|ARM64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|ARM64.Build.0 = Debug|ARM64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|x64.ActiveCfg = Debug|x64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|x64.Build.0 = Debug|x64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|x86.ActiveCfg = Debug|Win32
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Debug|x86.Build.0 = Debug|Win32
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|ARM.ActiveCfg = Release|ARM
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|ARM.Build.0 = Release|ARM
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|ARM64.ActiveCfg = Release|ARM64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|ARM64.Build.0 = Release|ARM64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|x64.ActiveCfg = Release|x64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|x64.Build.0 = Release|x64
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|x86.ActiveCfg = Release|Win32
{88754889-B2B2-44BE-9BE9-4DD21808206E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.daisy.pipeline.tts.onecore;

public class Onecore {

public static native long openConnection();

public static native int closeConnection(long connection);

public static native int speak(long connection, String voiceVendor, String voiceName, String text);
/* in bytes*/
public static native int getStreamSize(long connection);

/* returns the new offset */
public static native int readStream(long connection, byte[] dest, int offset);

public static native String[] getVoiceVendors();

public static native String[] getVoiceNames();

public static native String[] getVoiceLocales();

public static native String[] getVoiceGenders();

public static native String[] getVoiceAges();

public static native String[] getBookmarkNames(long connection);

/* in milliseconds */
public static native long[] getBookmarkPositions(long connection);

public static native int initialize();

public static native int dispose();

}
Loading

0 comments on commit 9f0cfc5

Please sign in to comment.