Skip to content

Commit

Permalink
Centralize definition of brand identifiers (#7)
Browse files Browse the repository at this point in the history
* Centralize definition of brand identifiers

Prior to this commit, the name of the Automation Voice and its "vendor"
were defined on an ad-hoc basis. This approach made it difficult to
understand how the brand information was used across the Visual Studio
projects, and this in turn made it difficult to infer and maintain
relationships between the values.

Introduce a Visual Studio "Shared Project" to define all brand
identifiers and reference those definitions consistently.

* Reuse shared file

* Remove import for unused library
  • Loading branch information
jugglinmike authored Dec 14, 2021
1 parent e051f24 commit 60fb169
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
5 changes: 5 additions & 0 deletions AutomationTtsEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AutomationTtsEngine", "src\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Vocalizer", "src\Vocalizer\Vocalizer.vcxproj", "{577A84E1-AFF0-481E-A69C-A9A23C643C1B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shared", "src\Shared\Shared.vcxitems", "{12ACE3FB-B82C-4A53-B3B9-277DD6115880}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Shared\Shared.vcxitems*{12ace3fb-b82c-4a53-b3b9-277dd6115880}*SharedItemsImports = 9
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Expand Down
19 changes: 19 additions & 0 deletions src/Shared/Shared.vcxitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{12ace3fb-b82c-4a53-b3b9-277dd6115880}</ItemsProjectGuid>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)branding.h" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/Shared/branding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#define AUTOMATION_VOICE_ID "BocoupAutomationVoice"
#define AUTOMATION_VOICE_NAME "Bocoup Automation Voice"
#define AUTOMATION_VOICE_VENDOR "Bocoup"
#define AUTOMATION_VOICE_HOME "C:\\Program Files\\Bocoup Automation Voice"
21 changes: 4 additions & 17 deletions src/Vocalizer/Vocalizer.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
#include "pch.h"
#include "..\Shared\branding.h"
#include <cstdlib>

using namespace System;
using namespace System::Speech::Synthesis;
using namespace System::Text::RegularExpressions;

/**
* Determine whether a given voice name likely indicates that the voice is
* intended for automation purposes and therefore inappropriate for use by this
* utility.
*
* TODO: Use a more precise heuristic based on references to the values this
* project uses to install the Automation Voice.
*/
bool isAutomation(String^ name)
{
return Regex::IsMatch(name, "automation", RegexOptions::IgnoreCase);
}

/**
* A process which vocalizes text data supplied as input via the environment
Expand Down Expand Up @@ -51,17 +38,17 @@ int main(array<System::String^>^ args)
// available value other than the Automation Voice in order to avoid
// problems in cases where the system has designated the Automation Voice
// as the "default" voice.
if (isAutomation(speaker.Voice->Name))
if (speaker.Voice->Name == AUTOMATION_VOICE_NAME)
{
for each (InstalledVoice^ voice in speaker.GetInstalledVoices())
{
if (!isAutomation(voice->VoiceInfo->Name))
if (voice->VoiceInfo->Name != AUTOMATION_VOICE_NAME)
{
speaker.SelectVoice(voice->VoiceInfo->Name);
break;
}
}
if (isAutomation(speaker.Voice->Name))
if (speaker.Voice->Name == AUTOMATION_VOICE_NAME)
{
Console::WriteLine(gcnew System::String(
"Unable to locate an authentic voice."
Expand Down
3 changes: 2 additions & 1 deletion src/automationttsengine/ttsengobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//--- Additional includes
#include "stdafx.h"
#include "TtsEngObj.h"
#include "..\Shared\branding.h"
#include <stdio.h>
#include <iostream>
#include <windows.h>
Expand Down Expand Up @@ -172,7 +173,7 @@ HRESULT vocalize(std::string text, ISpTTSEngineSite* pOutputSite)
ZeroMemory(&startup_info, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
ZeroMemory(&process_info, sizeof(process_info));
TCHAR command[] = TEXT("C:\\Program Files\\Bocoup Automation Voice\\Vocalizer.exe");
TCHAR command[] = TEXT(AUTOMATION_VOICE_HOME "\\Vocalizer.exe");
DWORD dwFlags = CREATE_NO_WINDOW;
TCHAR newEnv[SPEECH_BUFFER_SIZE];

Expand Down
15 changes: 8 additions & 7 deletions src/makevoice/MakeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* platform.
*/
#include "stdafx.h"
#include "..\Shared\branding.h"
#include <AutomationTtsEngine_i.c>
#include <direct.h>
#include <fstream>
Expand Down Expand Up @@ -61,11 +62,11 @@ int wmain(int argc, __in_ecount(argc) WCHAR* argv[])
CComPtr<ISpDataKey> cpDataKeyAttribs;
hr = SpCreateNewTokenEx(
SPCAT_VOICES,
L"BocoupAutomationVoice",
TEXT(AUTOMATION_VOICE_ID),
&CLSID_SampleTTSEngine,
L"Bocoup Automation Voice",
TEXT(AUTOMATION_VOICE_NAME),
0x409,
L"Bocoup Automation Voice",
TEXT(AUTOMATION_VOICE_NAME),
&cpToken,
&cpDataKeyAttribs
);
Expand All @@ -76,7 +77,7 @@ int wmain(int argc, __in_ecount(argc) WCHAR* argv[])
hr = cpDataKeyAttribs->SetStringValue(L"Gender", L"Male");
if (SUCCEEDED(hr))
{
hr = cpDataKeyAttribs->SetStringValue(L"Name", L"Bocoup Automation Voice");
hr = cpDataKeyAttribs->SetStringValue(L"Name", TEXT(AUTOMATION_VOICE_NAME));
}
if (SUCCEEDED(hr))
{
Expand All @@ -88,23 +89,23 @@ int wmain(int argc, __in_ecount(argc) WCHAR* argv[])
}
if (SUCCEEDED(hr))
{
hr = cpDataKeyAttribs->SetStringValue(L"Vendor", L"Bocoup");
hr = cpDataKeyAttribs->SetStringValue(L"Vendor", TEXT(AUTOMATION_VOICE_VENDOR));
}
}
}

if (SUCCEEDED(hr))
{
hr = createDirectoryIfAbsent(
L"C:\\Program Files\\Bocoup Automation Voice"
TEXT(AUTOMATION_VOICE_HOME)
);
}

if (SUCCEEDED(hr))
{
copyFile(
getSiblingFilePath("Vocalizer.exe").c_str(),
"C:\\Program Files\\Bocoup Automation Voice\\Vocalizer.exe"
AUTOMATION_VOICE_HOME "\\Vocalizer.exe"
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/makevoice/MakeVoice.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared" />
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
Expand Down Expand Up @@ -205,4 +206,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/makevoice/MakeVoice.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>

0 comments on commit 60fb169

Please sign in to comment.