Commit 15b44f4f authored by 姜春辉's avatar 姜春辉

代码库迁移

parent 0190d436
Pipeline #504 canceled with stages

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GS.Terminal.Speak", "Src\GS.Terminal.Speak.csproj", "{87FE52D6-E6AC-45C3-985C-4204911D14F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{87FE52D6-E6AC-45C3-985C-4204911D14F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87FE52D6-E6AC-45C3-985C-4204911D14F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87FE52D6-E6AC-45C3-985C-4204911D14F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87FE52D6-E6AC-45C3-985C-4204911D14F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AD782068-6D22-4E2F-BEE8-93FD1F764476}
EndGlobalSection
EndGlobal
# GS.Terminal.Speak # GS.Terminal.Speak
插件名称:
GS.Terminal.Speak
语音播报插件
初始版本:1.0
功能定义:
提供基于系统语音包的文本播报
XP 下需要安装语音包 MeiLing(在 DLL 目录下)
依赖插件:
版本历史:
1.0
实现 XP 及以上系统的语音播报
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GS.Unitive.Framework.Core;
using System.IO;
using SpeechLib;
using System.Speech.Synthesis;
using System.Threading.Tasks;
namespace GS.Terminal.Speak
{
public class Activator : IAddonActivator
{
public static IAddonContext AddContext;
private static int speakRate = 1;
internal static NAudioPlayer AudioPlayer;
public void Start(IAddonContext Context)
{
AddContext = Context;
var configRate = AddContext.DictionaryValue("baseConfig", "VoiceSpeed");
if (!int.TryParse(configRate, out speakRate))
{
speakRate = 1;
}
AudioPlayer = new NAudioPlayer();
}
public void Stop(IAddonContext Context)
{
AddContext = null;
}
static SpeechSynthesizer speak = null;
/// <summary>
/// 异步播放文本语音
/// </summary>
/// <param name="SpeakMessage"></param>
internal static void Voice(string SpeakMessage)
{
if (speak == null)
{
try
{
speak = new SpeechSynthesizer() { Volume = 100, Rate = speakRate };
}
catch (Exception ex)
{
AddContext.Logger.Error($"语音播报模块加载异常,请安装ScanSoft_MeiLing_ChineseMandarinVoice", ex);
return;
}
}
if (!string.IsNullOrEmpty(SpeakMessage))
{
speak.Speak(SpeakMessage);
}
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns="urn:Chinags-Configuration" AddonName="GS.Terminal.Speak">
<Dictionaries>
<Dict Name="baseConfig" Caption="基本设置">
<Key Name="VoiceSpeed" Value="1" Caption="语音播报速度" Choice="0,1,2,3,4,5" />
<Key Name="VoicePackage" Value="1" Caption="语音包序号" Choice="0,1,2,3" />
</Dict>
</Dictionaries>
</Settings>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{87FE52D6-E6AC-45C3-985C-4204911D14F9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GS.Terminal.Speak</RootNamespace>
<AssemblyName>GS.Terminal.Speak</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Release\GS.Terminal.Speak\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="GS.Unitive.Framework, Version=1.4.0.2, Culture=neutral, PublicKeyToken=769358b197600ab3, processorArchitecture=MSIL">
<HintPath>..\packages\GS.Unitive.Framework.1.4.0.2\lib\net40\GS.Unitive.Framework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NAudio, Version=1.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.10.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Deployment" />
<Reference Include="System.Speech" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Activator.cs" />
<Compile Include="NAudioPlayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Config.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Mapper.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<COMReference Include="SpeechLib">
<Guid>{C866CA3A-32F7-11D2-9602-00C04F8EE628}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>4</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Extensibility xmlns="urn:Chinags-Extensibility-1.0" Name="终端语音播报插件" SymbolicName="GS.Terminal.Speak" Version="1.0.0.0" StartLevel="10">
<License>ZIdlI0PmssjqRnU+teBUtPhVVlUGs51sqQW2K/B/8CK47gkBxo35i2/GK+6DDmKLdDKbDjY3NfCW3HjfsvajC3zLBXi8tBmfGG9CH59LyryQF2637T4KY4thHSmeluvwqOdh0USs8grFkx/Fphr/bHYKwPJJeCqp9QUBIk4XPKc=</License>
<Activator Type="GS.Terminal.Speak.Activator" />
<Runtime>
<Assembly Path="GS.Terminal.Speak.dll" Share="true" />
</Runtime>
<Services>
<Service Caption="语音播报服务" TypeAndName="GS.Terminal.Speak.Service">
<!--
/// <summary>
/// 播报文本语音
/// </summary>
/// <param name="SpeakMessage">文本内容</param>
public void Voice(string SpeakMessage)
-->
</Service>
</Services>
</Extensibility>
\ No newline at end of file
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GS.Terminal.Speak
{
public class NAudioPlayer
{
private const string wavDirectory = "Wav";
private Dictionary<string, Player> wavPlayer = new Dictionary<string, Player>();
public NAudioPlayer()
{
FindWav();
}
private void FindWav()
{
var newLocation = $"{Activator.AddContext.Addon.Location}\\{wavDirectory}";
var oldLocation = $"{Activator.AddContext.Addon.Location}";
if (!Directory.Exists(newLocation))
Directory.CreateDirectory(newLocation);
/*
* 之前wav文件直接放置在插件目录下,现在转移到wav文件夹下面
*/
var oldFiles = Directory.GetFiles(oldLocation, "*.wav", SearchOption.TopDirectoryOnly);
foreach (var oldfile in oldFiles)
{
File.Copy(oldfile, $"{newLocation}\\{Path.GetFileName(oldfile)}", true);
File.Delete(oldfile);
}
/*
* 查找并初始化播放器
*/
var wavFiles = Directory.GetFiles(newLocation, "*.wav", SearchOption.TopDirectoryOnly);
foreach (var wavfile in wavFiles)
{
var msg = Path.GetFileNameWithoutExtension(wavfile);
var player = new Player(wavfile);
wavPlayer.Add(msg, player);
}
}
public void Play(string msg)
{
if (!string.IsNullOrEmpty(msg))
if (wavPlayer.TryGetValue(msg, out Player player))
{
player.Play();
}
}
}
public class Player
{
public Player(string wavfile)
{
WavFile = wavfile;
PlayerOut = new WaveOut();
PlayerOut.PlaybackStopped += PlayerOut_PlaybackStopped;
Reader = new AudioFileReader(wavfile);
PlayerOut.Init(Reader);
}
private void PlayerOut_PlaybackStopped(object sender, StoppedEventArgs e)
{
if (Reader != null)
Reader.Position = 0;
}
public string WavFile { get; private set; }
public WaveOut PlayerOut { get; private set; }
public AudioFileReader Reader { get; private set; }
public void Play()
{
try
{
PlayerOut.Play();
}
catch (Exception ex)
{
Activator.AddContext.Logger.Error($"播放音频文件{WavFile}异常", ex);
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("GS.Terminal.Speak")]
[assembly: AssemblyDescription("终端语音播放插件")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1")]
[assembly: AssemblyFileVersion("1")]
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GS.Terminal.Speak
{
public class Service
{
/// <summary>
/// 播报文本语音
/// </summary>
/// <param name="SpeakMessage">文本内容</param>
public void Voice(string SpeakMessage)
{
Activator.Voice(SpeakMessage);
}
public void VoiceBySoundPlayer(string SpeakMessage, bool isAsync = true)
{
VoiceBySoundPlayer(SpeakMessage);
}
public void VoiceBySoundPlayer(string SpeakMessage)
{
Activator.AudioPlayer.Play(SpeakMessage);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GS.Unitive.Framework" version="1.4.0.2" targetFramework="net452" />
<package id="log4net" version="2.0.8" targetFramework="net452" />
<package id="NAudio" version="1.10.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment