Skip to content

Commit

Permalink
Add in Text To Speech and Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Oct 27, 2015
1 parent 1127ce3 commit 8c46e67
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 19 deletions.
9 changes: 9 additions & 0 deletions MonkeyApp/MonkeyApp.Droid/MonkeyApp.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\MonoAndroid10\Refractored.Xam.TTS.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS.Abstractions, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\MonoAndroid10\Refractored.Xam.TTS.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
Expand Down Expand Up @@ -92,6 +100,7 @@
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextToSpeech.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
21 changes: 21 additions & 0 deletions MonkeyApp/MonkeyApp.Droid/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions MonkeyApp/MonkeyApp.Droid/TextToSpeech.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

using System.Collections.Generic;
using MonkeyApp.Interfaces;
using Xamarin.Forms;
using Android.Speech.Tts;
using MonkeyApp.Droid;

[assembly:Dependency(typeof(TextToSpeech_Droid))]
namespace MonkeyApp.Droid
{
public class TextToSpeech_Droid : Java.Lang.Object, ITextToSpeech, TextToSpeech.IOnInitListener
{
TextToSpeech speaker;
string toSpeak;

public TextToSpeech_Droid() { }

public void Speak(string text)
{
var ctx = Forms.Context; // useful for many Android SDK features
toSpeak = text;
if (speaker == null)
{
speaker = new TextToSpeech(ctx, this);
}
else
{
var p = new Dictionary<string, string>();
speaker.Speak(toSpeak, QueueMode.Flush, p);
}
}

#region IOnInitListener implementation
public void OnInit(OperationResult status)
{
if (status.Equals(OperationResult.Success))
{
var p = new Dictionary<string, string>();
speaker.Speak(toSpeak, QueueMode.Flush, p);
}
}
#endregion
}
}
1 change: 1 addition & 0 deletions MonkeyApp/MonkeyApp.Droid/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="monoandroid6" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="monoandroid6" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="monoandroid6" />
<package id="Xam.Plugins.TextToSpeech" version="1.0.5" targetFramework="monoandroid6" />
<package id="Xamarin.Android.Support.v4" version="21.0.3.0" targetFramework="monoandroid6" />
<package id="Xamarin.Forms" version="1.3.3.6323" targetFramework="monoandroid6" />
</packages>
9 changes: 9 additions & 0 deletions MonkeyApp/MonkeyApp.WinPhone/MonkeyApp.WinPhone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.resx</DependentUpon>
</Compile>
<Compile Include="TextToSpeeh.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -173,6 +174,14 @@
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net45+wp80+win8+wpa81+dnxcore50\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\wp8\Refractored.Xam.TTS.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS.Abstractions, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\wp8\Refractored.Xam.TTS.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\sl4-windowsphone71\System.Net.Http.dll</HintPath>
<Private>True</Private>
Expand Down
41 changes: 23 additions & 18 deletions MonkeyApp/MonkeyApp.WinPhone/Properties/WMAppManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>

<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2012/deployment" AppPlatformVersion="8.0">
<DefaultLanguage xmlns="" code="en-US"/>
<App xmlns="" ProductID="{51345acb-a828-45e5-9781-2941a8d2c59e}" Title="MonkeyApp.WinPhone" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="MonkeyApp.WinPhone author" Description="Sample description" Publisher="MonkeyApp.WinPhone" PublisherID="{3ab0a07e-ad6f-445e-8403-5d3315ff324a}">
<DefaultLanguage xmlns="" code="en-US" />
<App xmlns="" ProductID="{51345acb-a828-45e5-9781-2941a8d2c59e}" Title="MonkeyApp.WinPhone" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="MonkeyApp.WinPhone author" Description="Sample description" Publisher="MonkeyApp.WinPhone" PublisherID="{3ab0a07e-ad6f-445e-8403-5d3315ff324a}">
<IconPath IsRelative="true" IsResource="false">Assets\ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_NETWORKING"/>
<Capability Name="ID_CAP_MEDIALIB_AUDIO"/>
<Capability Name="ID_CAP_MEDIALIB_PLAYBACK"/>
<Capability Name="ID_CAP_SENSORS"/>
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
<Capability Name="ID_CAP_NETWORKING" />
<Capability Name="ID_CAP_MEDIALIB_AUDIO" />
<Capability Name="ID_CAP_MEDIALIB_PLAYBACK" />
<Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
<Capability Name="ID_CAP_SPEECH_RECOGNITION" />
</Capabilities>
<Tasks>
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks>
<Tokens>
<PrimaryToken TokenID="PhoneApp1Token" TaskName="_default">
Expand All @@ -21,18 +21,23 @@
<Count>0</Count>
<BackgroundImageURI IsRelative="true" IsResource="false">Assets\Tiles\FlipCycleTileMedium.png</BackgroundImageURI>
<Title>MonkeyApp.WinPhone</Title>
<BackContent></BackContent>
<BackBackgroundImageURI></BackBackgroundImageURI>
<BackTitle></BackTitle>
<DeviceLockImageURI></DeviceLockImageURI>
<HasLarge></HasLarge>
<BackContent>
</BackContent>
<BackBackgroundImageURI>
</BackBackgroundImageURI>
<BackTitle>
</BackTitle>
<DeviceLockImageURI>
</DeviceLockImageURI>
<HasLarge>
</HasLarge>
</TemplateFlip>
</PrimaryToken>
</Tokens>
<ScreenResolutions>
<ScreenResolution Name="ID_RESOLUTION_WVGA"/>
<ScreenResolution Name="ID_RESOLUTION_WXGA"/>
<ScreenResolution Name="ID_RESOLUTION_HD720P"/>
<ScreenResolution Name="ID_RESOLUTION_WVGA" />
<ScreenResolution Name="ID_RESOLUTION_WXGA" />
<ScreenResolution Name="ID_RESOLUTION_HD720P" />
</ScreenResolutions>
</App>
</Deployment>
</Deployment>
17 changes: 17 additions & 0 deletions MonkeyApp/MonkeyApp.WinPhone/TextToSpeeh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MonkeyApp.Interfaces;
using System;
using Windows.Phone.Speech.Synthesis;

namespace MonkeyApp.WinPhone
{
public class TextToSpeech_WinPhone : ITextToSpeech
{
public TextToSpeech_WinPhone() { }

public async void Speak(string text)
{
var synth = new SpeechSynthesizer();
await synth.SpeakTextAsync(text);
}
}
}
1 change: 1 addition & 0 deletions MonkeyApp/MonkeyApp.WinPhone/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="wp8" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="wp8" />
<package id="WPtoolkit" version="4.2013.08.16" targetFramework="wp8" />
<package id="Xam.Plugins.TextToSpeech" version="1.0.5" targetFramework="wp8" />
<package id="Xamarin.Forms" version="1.3.3.6323" targetFramework="wp8" />
</packages>
9 changes: 9 additions & 0 deletions MonkeyApp/MonkeyApp.iOS/MonkeyApp.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="TextToSpeech.cs" />
<None Include="app.config" />
<None Include="Entitlements.plist" />
<None Include="Info.plist" />
Expand Down Expand Up @@ -126,6 +127,14 @@
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\Xamarin.iOS10\Refractored.Xam.TTS.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS.Abstractions, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\Xamarin.iOS10\Refractored.Xam.TTS.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\Xamarin.iOS10\System.Net.Http.Extensions.dll</HintPath>
Expand Down
28 changes: 28 additions & 0 deletions MonkeyApp/MonkeyApp.iOS/TextToSpeech.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using AVFoundation;
using MonkeyApp.Interfaces;
using MonkeyApp.iOS;
using Xamarin.Forms;

[assembly:Dependency(typeof(TextToSpeech))]
namespace MonkeyApp.iOS
{
public class TextToSpeech : ITextToSpeech
{
public TextToSpeech() { }

public void Speak(string text)
{
var speechSynthesizer = new AVSpeechSynthesizer();

var speechUtterance = new AVSpeechUtterance(text)
{
Rate = AVSpeechUtterance.MaximumSpeechRate / 4,
Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"),
Volume = 0.5f,
PitchMultiplier = 1.0f
};

speechSynthesizer.SpeakUtterance(speechUtterance);
}
}
}
1 change: 1 addition & 0 deletions MonkeyApp/MonkeyApp.iOS/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="xamarinios1" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="xamarinios1" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="xamarinios1" />
<package id="Xam.Plugins.TextToSpeech" version="1.0.5" targetFramework="xamarinios1" />
<package id="Xamarin.Forms" version="1.3.3.6323" targetFramework="xamarinios1" />
</packages>
13 changes: 13 additions & 0 deletions MonkeyApp/MonkeyApp/Interfaces/ITextToSpeech.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MonkeyApp.Interfaces
{
public interface ITextToSpeech
{
void Speak(string text);
}
}
9 changes: 9 additions & 0 deletions MonkeyApp/MonkeyApp/MonkeyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="Interfaces\ITextToSpeech.cs" />
<Compile Include="Model\Monkey.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModel\MonkeyListViewModel.cs" />
Expand All @@ -52,6 +53,14 @@
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Refractored.Xam.TTS.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Refractored.Xam.TTS.Abstractions, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.TextToSpeech.1.0.5\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Refractored.Xam.TTS.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll</HintPath>
<Private>True</Private>
Expand Down
1 change: 1 addition & 0 deletions MonkeyApp/MonkeyApp/View/MonkeyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Label Text="{Binding Monkey.Population, StringFormat='Population: {0}'}"/>
<Label Text="{Binding Monkey.Details}"/>
<Button x:Name="ButtonDismiss" Text="Dismiss"/>
<Button x:Name="ButtonSpeak" Text="Speak Monkey"/>
</StackLayout>
</ScrollView>
</ContentPage>
10 changes: 9 additions & 1 deletion MonkeyApp/MonkeyApp/View/MonkeyPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using MonkeyApp.Model;
using MonkeyApp.Interfaces;
using MonkeyApp.Model;
using MonkeyApp.ViewModel;
using Refractored.Xam.TTS;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,6 +23,12 @@ public MonkeyPage(Monkey monkey)
{
Navigation.PopAsync(true);
};

ButtonSpeak.Clicked += (sender, args) =>
{
//DependencyService.Get<ITextToSpeech>().Speak(monkey.Details);
CrossTextToSpeech.Current.Speak(monkey.Details);
};
}
}
}
1 change: 1 addition & 0 deletions MonkeyApp/MonkeyApp/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wp8" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="portable45-net45+win8+wp8" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="portable45-net45+win8+wp8" />
<package id="Xam.Plugins.TextToSpeech" version="1.0.5" targetFramework="portable45-net45+win8+wp8" />
<package id="Xamarin.Forms" version="1.3.3.6323" targetFramework="portable45-net45+win8+wp8" />
</packages>

0 comments on commit 8c46e67

Please sign in to comment.