@iternio/react-native-tts 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +268 -0
- package/TextToSpeech.podspec +21 -0
- package/android/build.gradle +41 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java +538 -0
- package/android/src/main/java/net/no_mad/tts/TextToSpeechPackage.java +31 -0
- package/index.d.ts +118 -0
- package/index.js +127 -0
- package/ios/TextToSpeech/TextToSpeech.h +20 -0
- package/ios/TextToSpeech/TextToSpeech.m +285 -0
- package/ios/TextToSpeech.xcodeproj/project.pbxproj +276 -0
- package/ios/TextToSpeech.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/TextToSpeech.xcodeproj/project.xcworkspace/xcuserdata/anton.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +5 -0
- package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/TextToSpeech.xcscheme +80 -0
- package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- package/package.json +27 -0
- package/windows/README.md +25 -0
- package/windows/RNTTS/PropertySheet.props +16 -0
- package/windows/RNTTS/RNTTS.cpp +224 -0
- package/windows/RNTTS/RNTTS.def +3 -0
- package/windows/RNTTS/RNTTS.h +75 -0
- package/windows/RNTTS/RNTTS.vcxproj +163 -0
- package/windows/RNTTS/RNTTS.vcxproj.filters +33 -0
- package/windows/RNTTS/ReactPackageProvider.cpp +15 -0
- package/windows/RNTTS/ReactPackageProvider.h +16 -0
- package/windows/RNTTS/ReactPackageProvider.idl +9 -0
- package/windows/RNTTS/packages.config +4 -0
- package/windows/RNTTS/pch.cpp +1 -0
- package/windows/RNTTS/pch.h +11 -0
- package/windows/RNTTS62.sln +254 -0
- package/windows/RNTTS63.sln +226 -0
|
Binary file
|
package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/TextToSpeech.xcscheme
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<Scheme
|
|
3
|
+
LastUpgradeVersion = "0800"
|
|
4
|
+
version = "1.3">
|
|
5
|
+
<BuildAction
|
|
6
|
+
parallelizeBuildables = "YES"
|
|
7
|
+
buildImplicitDependencies = "YES">
|
|
8
|
+
<BuildActionEntries>
|
|
9
|
+
<BuildActionEntry
|
|
10
|
+
buildForTesting = "YES"
|
|
11
|
+
buildForRunning = "YES"
|
|
12
|
+
buildForProfiling = "YES"
|
|
13
|
+
buildForArchiving = "YES"
|
|
14
|
+
buildForAnalyzing = "YES">
|
|
15
|
+
<BuildableReference
|
|
16
|
+
BuildableIdentifier = "primary"
|
|
17
|
+
BlueprintIdentifier = "3A6FB2071D99E12200593599"
|
|
18
|
+
BuildableName = "libTextToSpeech.a"
|
|
19
|
+
BlueprintName = "TextToSpeech"
|
|
20
|
+
ReferencedContainer = "container:TextToSpeech.xcodeproj">
|
|
21
|
+
</BuildableReference>
|
|
22
|
+
</BuildActionEntry>
|
|
23
|
+
</BuildActionEntries>
|
|
24
|
+
</BuildAction>
|
|
25
|
+
<TestAction
|
|
26
|
+
buildConfiguration = "Debug"
|
|
27
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
28
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
29
|
+
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
30
|
+
<Testables>
|
|
31
|
+
</Testables>
|
|
32
|
+
<AdditionalOptions>
|
|
33
|
+
</AdditionalOptions>
|
|
34
|
+
</TestAction>
|
|
35
|
+
<LaunchAction
|
|
36
|
+
buildConfiguration = "Debug"
|
|
37
|
+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
38
|
+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
39
|
+
launchStyle = "0"
|
|
40
|
+
useCustomWorkingDirectory = "NO"
|
|
41
|
+
ignoresPersistentStateOnLaunch = "NO"
|
|
42
|
+
debugDocumentVersioning = "YES"
|
|
43
|
+
debugServiceExtension = "internal"
|
|
44
|
+
allowLocationSimulation = "YES">
|
|
45
|
+
<MacroExpansion>
|
|
46
|
+
<BuildableReference
|
|
47
|
+
BuildableIdentifier = "primary"
|
|
48
|
+
BlueprintIdentifier = "3A6FB2071D99E12200593599"
|
|
49
|
+
BuildableName = "libTextToSpeech.a"
|
|
50
|
+
BlueprintName = "TextToSpeech"
|
|
51
|
+
ReferencedContainer = "container:TextToSpeech.xcodeproj">
|
|
52
|
+
</BuildableReference>
|
|
53
|
+
</MacroExpansion>
|
|
54
|
+
<AdditionalOptions>
|
|
55
|
+
</AdditionalOptions>
|
|
56
|
+
</LaunchAction>
|
|
57
|
+
<ProfileAction
|
|
58
|
+
buildConfiguration = "Release"
|
|
59
|
+
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
60
|
+
savedToolIdentifier = ""
|
|
61
|
+
useCustomWorkingDirectory = "NO"
|
|
62
|
+
debugDocumentVersioning = "YES">
|
|
63
|
+
<MacroExpansion>
|
|
64
|
+
<BuildableReference
|
|
65
|
+
BuildableIdentifier = "primary"
|
|
66
|
+
BlueprintIdentifier = "3A6FB2071D99E12200593599"
|
|
67
|
+
BuildableName = "libTextToSpeech.a"
|
|
68
|
+
BlueprintName = "TextToSpeech"
|
|
69
|
+
ReferencedContainer = "container:TextToSpeech.xcodeproj">
|
|
70
|
+
</BuildableReference>
|
|
71
|
+
</MacroExpansion>
|
|
72
|
+
</ProfileAction>
|
|
73
|
+
<AnalyzeAction
|
|
74
|
+
buildConfiguration = "Debug">
|
|
75
|
+
</AnalyzeAction>
|
|
76
|
+
<ArchiveAction
|
|
77
|
+
buildConfiguration = "Release"
|
|
78
|
+
revealArchiveInOrganizer = "YES">
|
|
79
|
+
</ArchiveAction>
|
|
80
|
+
</Scheme>
|
package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/xcschememanagement.plist
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>TextToSpeech.xcscheme</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
<key>SuppressBuildableAutocreation</key>
|
|
14
|
+
<dict>
|
|
15
|
+
<key>3A6FB2071D99E12200593599</key>
|
|
16
|
+
<dict>
|
|
17
|
+
<key>primary</key>
|
|
18
|
+
<true/>
|
|
19
|
+
</dict>
|
|
20
|
+
</dict>
|
|
21
|
+
</dict>
|
|
22
|
+
</plist>
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iternio/react-native-tts",
|
|
3
|
+
"version": "4.1.2",
|
|
4
|
+
"description": "React Native Text-To-Speech module for Android and iOS",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Iternio-Planning-AB/react-native-tts.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"tts",
|
|
12
|
+
"voice",
|
|
13
|
+
"speech",
|
|
14
|
+
"text-to-speech",
|
|
15
|
+
"react",
|
|
16
|
+
"react-native",
|
|
17
|
+
"android",
|
|
18
|
+
"ios"
|
|
19
|
+
],
|
|
20
|
+
"author": "Manuel Auer <g4rb4g3@gmail.com> (https://github.com/g4rb4g3)",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/Iternio-Planning-AB/react-native-tts#readme",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org/",
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# react-native-tts Windows Implementation
|
|
2
|
+
|
|
3
|
+
## Module Installation
|
|
4
|
+
You can either use autolinking on react-native-windows 0.63 and later or manually link the module on earlier releases.
|
|
5
|
+
|
|
6
|
+
## Automatic install with autolinking on RNW >= 0.63
|
|
7
|
+
RNTTS supports autolinking. Just call: `npm i react-native-tts --save`
|
|
8
|
+
|
|
9
|
+
## Manual installation on RNW >= 0.62
|
|
10
|
+
1. `npm install react-native-tts --save`
|
|
11
|
+
2. Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
|
|
12
|
+
3. Right-click Solution icon in Solution Explorer > Add > Existing Project...
|
|
13
|
+
4. Add `node_modules\react-native-tts\windows\RNTTS\RNTTS.vcxproj`
|
|
14
|
+
5. Right-click main application project > Add > Reference...
|
|
15
|
+
6. Select `RNTTS` in Solution Projects
|
|
16
|
+
7. In app `pch.h` add `#include "winrt/RNTTS.h"`
|
|
17
|
+
8. In `App.cpp` add `PackageProviders().Append(winrt::RNTTS::ReactPackageProvider());` before `InitializeComponent();`
|
|
18
|
+
|
|
19
|
+
## Module development
|
|
20
|
+
|
|
21
|
+
If you want to contribute to this module Windows implementation, first you must install the [Windows Development Dependencies](https://aka.ms/rnw-deps).
|
|
22
|
+
|
|
23
|
+
You must temporarily install the `react-native-windows` package. Versions of `react-native-windows` and `react-native` must match, e.g. if the module uses `react-native@0.62`, install `npm i react-native-windows@^0.62 --dev`.
|
|
24
|
+
|
|
25
|
+
Now, you will be able to open corresponding `RNTTS...sln` file, e.g. `RNTTS62.sln` for `react-native-windows@0.62`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
3
|
+
<ImportGroup Label="PropertySheets" />
|
|
4
|
+
<PropertyGroup Label="UserMacros" />
|
|
5
|
+
<!--
|
|
6
|
+
To customize common C++/WinRT project properties:
|
|
7
|
+
* right-click the project node
|
|
8
|
+
* expand the Common Properties item
|
|
9
|
+
* select the C++/WinRT property page
|
|
10
|
+
|
|
11
|
+
For more advanced scenarios, and complete documentation, please see:
|
|
12
|
+
https://github.com/Microsoft/xlang/tree/master/src/package/cppwinrt/nuget
|
|
13
|
+
-->
|
|
14
|
+
<PropertyGroup />
|
|
15
|
+
<ItemDefinitionGroup />
|
|
16
|
+
</Project>
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#include "pch.h"
|
|
2
|
+
#include "RNTTS.h"
|
|
3
|
+
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
using namespace winrt;
|
|
8
|
+
using namespace winrt::Windows::UI::Xaml::Media;
|
|
9
|
+
using namespace winrt::Windows::Media::Playback;
|
|
10
|
+
|
|
11
|
+
RNTTS::RNTTS::RNTTS() : defaultVoice(nullptr)
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void RNTTS::RNTTS::Init(React::ReactContext const& _reactContext) noexcept
|
|
17
|
+
{
|
|
18
|
+
reactContext = _reactContext;
|
|
19
|
+
speechSynthesizer = SpeechSynthesizer{};
|
|
20
|
+
mediaPlayer = MediaPlayer{};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void RNTTS::RNTTS::SetDefaultVoice(std::string voiceId, ReactPromise<JSValue> promise) noexcept
|
|
24
|
+
{
|
|
25
|
+
bool wasFound = false;
|
|
26
|
+
size_t numVoices = speechSynthesizer.AllVoices().Size();
|
|
27
|
+
for (size_t i = 0; i < numVoices; i++)
|
|
28
|
+
{
|
|
29
|
+
VoiceInformation voiceInfo = speechSynthesizer.AllVoices().GetAt((uint32_t)i);
|
|
30
|
+
if (winrt::to_string(voiceInfo.Id()) == voiceId || winrt::to_string(voiceInfo.DisplayName()) == voiceId)
|
|
31
|
+
{
|
|
32
|
+
wasFound = true;
|
|
33
|
+
defaultVoice = voiceInfo;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!wasFound)
|
|
39
|
+
{
|
|
40
|
+
promise.Reject("The selected voice was not found");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try
|
|
45
|
+
{
|
|
46
|
+
speechSynthesizer.Voice(defaultVoice);
|
|
47
|
+
promise.Resolve("success");
|
|
48
|
+
}
|
|
49
|
+
catch (winrt::hresult_error const&)
|
|
50
|
+
{
|
|
51
|
+
promise.Reject("Error setting selected voice");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void RNTTS::RNTTS::SetDefaultRate(double rate, bool skipTransform, ReactPromise<JSValue> promise) noexcept
|
|
56
|
+
{
|
|
57
|
+
// This value can range from 0.5 (half the default rate) to 6.0 (6x the default rate), inclusive.
|
|
58
|
+
// The default value is 1.0 (the "normal" speaking rate for the current voice).
|
|
59
|
+
if (skipTransform)
|
|
60
|
+
{
|
|
61
|
+
if (rate < 0.5 || rate > 6.0)
|
|
62
|
+
{
|
|
63
|
+
promise.Reject("Failure caused by an invalid rate");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
speechSynthesizer.Options().SpeakingRate(rate);
|
|
68
|
+
promise.Resolve("success");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Convert a number range to another range, maintaining ratio
|
|
73
|
+
const double oldMin = 0.5;
|
|
74
|
+
double oldRange = (1.0 - oldMin);
|
|
75
|
+
const double newMin = 1.0;
|
|
76
|
+
double newRange = (6.0 - newMin);
|
|
77
|
+
|
|
78
|
+
double transformedRate = rate < 0.5f ?
|
|
79
|
+
rate * 2 : // linear fit {0, 0}, {0.25, 0.5}, {0.5, 1}
|
|
80
|
+
(((rate - oldMin) * newRange) / oldRange) + newMin;
|
|
81
|
+
speechSynthesizer.Options().SpeakingRate(transformedRate);
|
|
82
|
+
|
|
83
|
+
promise.Resolve("success");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void RNTTS::RNTTS::SetDefaultPitch(double pitch, ReactPromise<JSValue> promise) noexcept
|
|
87
|
+
{
|
|
88
|
+
// This value can range from 0.0 (lowest pitch) to 2.0 (highest pitch), inclusive. The default value is 1.0.
|
|
89
|
+
if (pitch < 0.0 || pitch > 2.0)
|
|
90
|
+
{
|
|
91
|
+
promise.Reject("Failure caused by an invalid pitch");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
speechSynthesizer.Options().AudioPitch(pitch);
|
|
96
|
+
|
|
97
|
+
promise.Resolve("success");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void RNTTS::RNTTS::SetDefaultLanguage(std::string language, ReactPromise<JSValue> promise) noexcept
|
|
101
|
+
{
|
|
102
|
+
bool wasFound = false;
|
|
103
|
+
size_t numVoices = speechSynthesizer.AllVoices().Size();
|
|
104
|
+
for (size_t i = 0; i < numVoices; i++)
|
|
105
|
+
{
|
|
106
|
+
VoiceInformation voiceInfo = speechSynthesizer.AllVoices().GetAt((uint32_t)i);
|
|
107
|
+
if (winrt::to_string(voiceInfo.Language()) == language)
|
|
108
|
+
{
|
|
109
|
+
wasFound = true;
|
|
110
|
+
defaultVoice = voiceInfo;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!wasFound)
|
|
116
|
+
{
|
|
117
|
+
promise.Reject("The selected voice was not found");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try
|
|
122
|
+
{
|
|
123
|
+
speechSynthesizer.Voice(defaultVoice);
|
|
124
|
+
promise.Resolve("success");
|
|
125
|
+
}
|
|
126
|
+
catch(winrt::hresult_error const&)
|
|
127
|
+
{
|
|
128
|
+
promise.Reject("Error setting selected voice");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void RNTTS::RNTTS::Voices(ReactPromise<JSValueArray> promise) noexcept
|
|
133
|
+
{
|
|
134
|
+
JSValueArray voices;
|
|
135
|
+
|
|
136
|
+
size_t numVoices = speechSynthesizer.AllVoices().Size();
|
|
137
|
+
for (size_t i = 0; i < numVoices; i++)
|
|
138
|
+
{
|
|
139
|
+
VoiceInformation voiceInfo = speechSynthesizer.AllVoices().GetAt((uint32_t)i);
|
|
140
|
+
|
|
141
|
+
JSValueObject voice;
|
|
142
|
+
voice["id"] = winrt::to_string(voiceInfo.Id());
|
|
143
|
+
voice["gender"] = winrt::to_string(voiceInfo.Gender() == VoiceGender::Male ? L"male" : L"female");
|
|
144
|
+
voice["name"] = winrt::to_string(voiceInfo.DisplayName());
|
|
145
|
+
voice["language"] = winrt::to_string(voiceInfo.Language());
|
|
146
|
+
voice["quality"] = 300;
|
|
147
|
+
|
|
148
|
+
voices.emplace_back(std::move(voice));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
promise.Resolve(voices);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void RNTTS::RNTTS::Speak(std::string text, ReactPromise<JSValue> promise) noexcept
|
|
155
|
+
{
|
|
156
|
+
winrt::hstring htext = winrt::to_hstring(text);
|
|
157
|
+
SpeakAsync(htext, promise);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
void RNTTS::RNTTS::Stop(ReactPromise<JSValue> promise) noexcept
|
|
161
|
+
{
|
|
162
|
+
Pause(promise);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void RNTTS::RNTTS::Pause(ReactPromise<JSValue> promise) noexcept
|
|
166
|
+
{
|
|
167
|
+
if (mediaPlayer.CanPause())
|
|
168
|
+
mediaPlayer.Pause();
|
|
169
|
+
|
|
170
|
+
promise.Resolve("success");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
void RNTTS::RNTTS::Resume(ReactPromise<JSValue> promise) noexcept
|
|
174
|
+
{
|
|
175
|
+
mediaPlayer.Play();
|
|
176
|
+
|
|
177
|
+
promise.Resolve("success");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
winrt::Windows::Foundation::IAsyncAction RNTTS::RNTTS::SpeakAsync(winrt::hstring text, ReactPromise<JSValue> promise) noexcept
|
|
181
|
+
{
|
|
182
|
+
// Generate the audio stream from plain text.
|
|
183
|
+
winrt::Windows::Foundation::IAsyncOperation<SpeechSynthesisStream> task{ speechSynthesizer.SynthesizeTextToStreamAsync(text) };
|
|
184
|
+
|
|
185
|
+
SpeechSynthesisStream speechStream = co_await task;
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
// Send the stream to the media object.
|
|
190
|
+
MediaPlaybackSession mediaSession = mediaPlayer.PlaybackSession();
|
|
191
|
+
mediaSession.PlaybackStateChanged({ this, &RNTTS::RNTTS::OnMediaElementStateChanged });
|
|
192
|
+
|
|
193
|
+
mediaPlayer.SetStreamSource(speechStream);
|
|
194
|
+
//mediaPlayer.Source(speechStream);
|
|
195
|
+
mediaPlayer.AutoPlay(true);
|
|
196
|
+
mediaPlayer.Volume(100);
|
|
197
|
+
mediaPlayer.Play();
|
|
198
|
+
|
|
199
|
+
promise.Resolve("success");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
void RNTTS::RNTTS::OnMediaElementStateChanged(MediaPlaybackSession session,
|
|
203
|
+
winrt::Windows::Foundation::IInspectable const&) noexcept
|
|
204
|
+
{
|
|
205
|
+
#if 1
|
|
206
|
+
const void* address = static_cast<const void*>(&session);
|
|
207
|
+
std::stringstream ss;
|
|
208
|
+
ss << address;
|
|
209
|
+
std::string id = ss.str();
|
|
210
|
+
|
|
211
|
+
switch (session.PlaybackState())
|
|
212
|
+
{
|
|
213
|
+
case MediaPlaybackState::Buffering:
|
|
214
|
+
case MediaPlaybackState::Opening:
|
|
215
|
+
return;
|
|
216
|
+
case MediaPlaybackState::Playing:
|
|
217
|
+
OnStart(id);
|
|
218
|
+
return;
|
|
219
|
+
case MediaPlaybackState::Paused:
|
|
220
|
+
OnFinish(id);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
#endif
|
|
224
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "pch.h"
|
|
4
|
+
#include "NativeModules.h"
|
|
5
|
+
|
|
6
|
+
using namespace winrt::Microsoft::ReactNative;
|
|
7
|
+
using namespace winrt::Windows::Media::Playback;
|
|
8
|
+
using namespace winrt::Windows::Media::SpeechSynthesis;
|
|
9
|
+
using namespace winrt::Windows::UI::Xaml::Controls;
|
|
10
|
+
|
|
11
|
+
#ifdef RNW61
|
|
12
|
+
#define JSVALUEOBJECTPARAMETER
|
|
13
|
+
#else
|
|
14
|
+
#define JSVALUEOBJECTPARAMETER const &
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
namespace winrt::RNTTS {
|
|
18
|
+
REACT_MODULE(RNTTS, L"TextToSpeech");
|
|
19
|
+
struct RNTTS {
|
|
20
|
+
const std::string Name = "TextToSpeech";
|
|
21
|
+
|
|
22
|
+
SpeechSynthesizer speechSynthesizer;
|
|
23
|
+
MediaPlayer mediaPlayer;
|
|
24
|
+
VoiceInformation defaultVoice;
|
|
25
|
+
React::ReactContext reactContext;
|
|
26
|
+
|
|
27
|
+
RNTTS();
|
|
28
|
+
|
|
29
|
+
winrt::Windows::Foundation::IAsyncAction SpeakAsync(winrt::hstring text, ReactPromise<JSValue> promise) noexcept;
|
|
30
|
+
void OnMediaElementStateChanged(MediaPlaybackSession session,
|
|
31
|
+
winrt::Windows::Foundation::IInspectable const& result) noexcept;
|
|
32
|
+
|
|
33
|
+
REACT_INIT(Init);
|
|
34
|
+
void Init(React::ReactContext const& reactContext) noexcept;
|
|
35
|
+
|
|
36
|
+
REACT_METHOD(SetDefaultVoice, L"setDefaultVoice")
|
|
37
|
+
void SetDefaultVoice(std::string voiceId, ReactPromise<JSValue> promise) noexcept;
|
|
38
|
+
|
|
39
|
+
REACT_METHOD(SetDefaultRate, L"setDefaultRate")
|
|
40
|
+
void SetDefaultRate(double rate, bool skipTransform, ReactPromise<JSValue> promise) noexcept;
|
|
41
|
+
|
|
42
|
+
REACT_METHOD(SetDefaultPitch, L"setDefaultPitch")
|
|
43
|
+
void SetDefaultPitch(double rate, ReactPromise<JSValue> promise) noexcept;
|
|
44
|
+
|
|
45
|
+
REACT_METHOD(SetDefaultLanguage, L"setDefaultLanguage")
|
|
46
|
+
void SetDefaultLanguage(std::string language, ReactPromise<JSValue> promise) noexcept;
|
|
47
|
+
|
|
48
|
+
REACT_METHOD(Voices, L"voices")
|
|
49
|
+
void Voices(ReactPromise<JSValueArray> promise) noexcept;
|
|
50
|
+
|
|
51
|
+
REACT_METHOD(Speak, L"speak")
|
|
52
|
+
void Speak(std::string text, ReactPromise<JSValue> promise) noexcept;
|
|
53
|
+
|
|
54
|
+
REACT_METHOD(Stop, L"stop")
|
|
55
|
+
void Stop(ReactPromise<JSValue> promise) noexcept;
|
|
56
|
+
|
|
57
|
+
REACT_METHOD(Pause, L"pause")
|
|
58
|
+
void Pause(ReactPromise<JSValue> promise) noexcept;
|
|
59
|
+
|
|
60
|
+
REACT_METHOD(Resume, L"resume")
|
|
61
|
+
void Resume(ReactPromise<JSValue> promise) noexcept;
|
|
62
|
+
|
|
63
|
+
REACT_EVENT(OnStart, L"tts-start");
|
|
64
|
+
std::function<void(std::string)> OnStart;
|
|
65
|
+
|
|
66
|
+
REACT_EVENT(OnFinish, L"tts-finish");
|
|
67
|
+
std::function<void(std::string)> OnFinish;
|
|
68
|
+
|
|
69
|
+
REACT_EVENT(OnError, L"tts-error");
|
|
70
|
+
std::function<void(std::string)> OnError;
|
|
71
|
+
|
|
72
|
+
REACT_EVENT(OnCancel, L"tts-cancel");
|
|
73
|
+
std::function<void(std::string)> OnCancel;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
3
|
+
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" />
|
|
4
|
+
<PropertyGroup Label="Globals">
|
|
5
|
+
<CppWinRTOptimized>true</CppWinRTOptimized>
|
|
6
|
+
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
|
|
7
|
+
<MinimalCoreWin>true</MinimalCoreWin>
|
|
8
|
+
<ProjectGuid>{B250B404-D1A2-4171-851E-E80BA031DAF0}</ProjectGuid>
|
|
9
|
+
<ProjectName>RNTTS</ProjectName>
|
|
10
|
+
<RootNamespace>RNTTS</RootNamespace>
|
|
11
|
+
<DefaultLanguage>en-US</DefaultLanguage>
|
|
12
|
+
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
|
|
13
|
+
<AppContainerApplication>true</AppContainerApplication>
|
|
14
|
+
<ApplicationType>Windows Store</ApplicationType>
|
|
15
|
+
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
|
16
|
+
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
|
|
17
|
+
<WindowsTargetPlatformMinVersion>10.0.16299.0</WindowsTargetPlatformMinVersion>
|
|
18
|
+
</PropertyGroup>
|
|
19
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
20
|
+
<PropertyGroup Label="ReactNativeWindowsProps">
|
|
21
|
+
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
|
|
22
|
+
</PropertyGroup>
|
|
23
|
+
<ItemGroup Label="ProjectConfigurations">
|
|
24
|
+
<ProjectConfiguration Include="Debug|ARM">
|
|
25
|
+
<Configuration>Debug</Configuration>
|
|
26
|
+
<Platform>ARM</Platform>
|
|
27
|
+
</ProjectConfiguration>
|
|
28
|
+
<ProjectConfiguration Include="Debug|ARM64">
|
|
29
|
+
<Configuration>Debug</Configuration>
|
|
30
|
+
<Platform>ARM64</Platform>
|
|
31
|
+
</ProjectConfiguration>
|
|
32
|
+
<ProjectConfiguration Include="Debug|Win32">
|
|
33
|
+
<Configuration>Debug</Configuration>
|
|
34
|
+
<Platform>Win32</Platform>
|
|
35
|
+
</ProjectConfiguration>
|
|
36
|
+
<ProjectConfiguration Include="Debug|x64">
|
|
37
|
+
<Configuration>Debug</Configuration>
|
|
38
|
+
<Platform>x64</Platform>
|
|
39
|
+
</ProjectConfiguration>
|
|
40
|
+
<ProjectConfiguration Include="Release|ARM">
|
|
41
|
+
<Configuration>Release</Configuration>
|
|
42
|
+
<Platform>ARM</Platform>
|
|
43
|
+
</ProjectConfiguration>
|
|
44
|
+
<ProjectConfiguration Include="Release|ARM64">
|
|
45
|
+
<Configuration>Release</Configuration>
|
|
46
|
+
<Platform>ARM64</Platform>
|
|
47
|
+
</ProjectConfiguration>
|
|
48
|
+
<ProjectConfiguration Include="Release|Win32">
|
|
49
|
+
<Configuration>Release</Configuration>
|
|
50
|
+
<Platform>Win32</Platform>
|
|
51
|
+
</ProjectConfiguration>
|
|
52
|
+
<ProjectConfiguration Include="Release|x64">
|
|
53
|
+
<Configuration>Release</Configuration>
|
|
54
|
+
<Platform>x64</Platform>
|
|
55
|
+
</ProjectConfiguration>
|
|
56
|
+
</ItemGroup>
|
|
57
|
+
<PropertyGroup Label="Configuration">
|
|
58
|
+
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
|
59
|
+
<CharacterSet>Unicode</CharacterSet>
|
|
60
|
+
<GenerateManifest>false</GenerateManifest>
|
|
61
|
+
</PropertyGroup>
|
|
62
|
+
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
|
63
|
+
<UseDebugLibraries>true</UseDebugLibraries>
|
|
64
|
+
<LinkIncremental>true</LinkIncremental>
|
|
65
|
+
</PropertyGroup>
|
|
66
|
+
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
|
67
|
+
<UseDebugLibraries>false</UseDebugLibraries>
|
|
68
|
+
<WholeProgramOptimization>true</WholeProgramOptimization>
|
|
69
|
+
<LinkIncremental>false</LinkIncremental>
|
|
70
|
+
</PropertyGroup>
|
|
71
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
72
|
+
<ImportGroup Label="ExtensionSettings">
|
|
73
|
+
</ImportGroup>
|
|
74
|
+
<ImportGroup Label="PropertySheets">
|
|
75
|
+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
76
|
+
</ImportGroup>
|
|
77
|
+
<ImportGroup Label="PropertySheets">
|
|
78
|
+
<Import Project="PropertySheet.props" />
|
|
79
|
+
</ImportGroup>
|
|
80
|
+
<ImportGroup Label="ReactNativeWindowsPropertySheets">
|
|
81
|
+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" />
|
|
82
|
+
</ImportGroup>
|
|
83
|
+
<PropertyGroup Label="UserMacros" />
|
|
84
|
+
<PropertyGroup />
|
|
85
|
+
<ItemDefinitionGroup>
|
|
86
|
+
<ClCompile>
|
|
87
|
+
<PrecompiledHeader>Use</PrecompiledHeader>
|
|
88
|
+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
|
89
|
+
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
|
90
|
+
<WarningLevel>Level4</WarningLevel>
|
|
91
|
+
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
|
|
92
|
+
<!--Temporarily disable cppwinrt heap enforcement to work around xaml compiler generated std::shared_ptr use -->
|
|
93
|
+
<AdditionalOptions Condition="'$(CppWinRTHeapEnforcement)'==''">/DWINRT_NO_MAKE_DETECTION %(AdditionalOptions)</AdditionalOptions>
|
|
94
|
+
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
|
|
95
|
+
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
96
|
+
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
|
97
|
+
</ClCompile>
|
|
98
|
+
<Link>
|
|
99
|
+
<SubSystem>Console</SubSystem>
|
|
100
|
+
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
|
|
101
|
+
<ModuleDefinitionFile>RNTTS.def</ModuleDefinitionFile>
|
|
102
|
+
</Link>
|
|
103
|
+
</ItemDefinitionGroup>
|
|
104
|
+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
|
105
|
+
<ClCompile>
|
|
106
|
+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
107
|
+
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
108
|
+
</ClCompile>
|
|
109
|
+
</ItemDefinitionGroup>
|
|
110
|
+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
|
111
|
+
<ClCompile>
|
|
112
|
+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
113
|
+
</ClCompile>
|
|
114
|
+
</ItemDefinitionGroup>
|
|
115
|
+
<ItemGroup>
|
|
116
|
+
<ClInclude Include="pch.h" />
|
|
117
|
+
<ClInclude Include="ReactPackageProvider.h">
|
|
118
|
+
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
|
|
119
|
+
</ClInclude>
|
|
120
|
+
<ClInclude Include="RNTTS.h" />
|
|
121
|
+
</ItemGroup>
|
|
122
|
+
<ItemGroup>
|
|
123
|
+
<ClCompile Include="pch.cpp">
|
|
124
|
+
<PrecompiledHeader>Create</PrecompiledHeader>
|
|
125
|
+
</ClCompile>
|
|
126
|
+
<ClCompile Include="ReactPackageProvider.cpp">
|
|
127
|
+
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
|
|
128
|
+
</ClCompile>
|
|
129
|
+
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
|
|
130
|
+
<ClCompile Include="RNTTS.cpp" />
|
|
131
|
+
</ItemGroup>
|
|
132
|
+
<ItemGroup>
|
|
133
|
+
<Midl Include="ReactPackageProvider.idl" />
|
|
134
|
+
</ItemGroup>
|
|
135
|
+
<ItemGroup>
|
|
136
|
+
<None Include="packages.config" />
|
|
137
|
+
<None Include="RNTTS.def" />
|
|
138
|
+
</ItemGroup>
|
|
139
|
+
<ItemGroup>
|
|
140
|
+
<None Include="PropertySheet.props" />
|
|
141
|
+
</ItemGroup>
|
|
142
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
143
|
+
<ImportGroup Label="ReactNativeWindowsTargets">
|
|
144
|
+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" />
|
|
145
|
+
</ImportGroup>
|
|
146
|
+
<Target Name="EnsureReactNativeWindowsTargets" BeforeTargets="PrepareForBuild">
|
|
147
|
+
<PropertyGroup>
|
|
148
|
+
<ErrorText>This project references targets in your node_modules\react-native-windows folder. The missing file is {0}.</ErrorText>
|
|
149
|
+
</PropertyGroup>
|
|
150
|
+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
|
|
151
|
+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
|
|
152
|
+
</Target>
|
|
153
|
+
<ImportGroup Label="ExtensionTargets">
|
|
154
|
+
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
|
155
|
+
</ImportGroup>
|
|
156
|
+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
|
157
|
+
<PropertyGroup>
|
|
158
|
+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
|
159
|
+
</PropertyGroup>
|
|
160
|
+
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
|
161
|
+
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
|
162
|
+
</Target>
|
|
163
|
+
</Project>
|