Skip to content

Commit 07fc45f

Browse files
committed
Adding simple TTS with Azure Cognitive Services
1 parent 6d50afc commit 07fc45f

File tree

16 files changed

+1372
-18
lines changed

16 files changed

+1372
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,4 @@ MigrationBackup/
358358

359359
# Fody - auto-generated XML schema
360360
FodyWeavers.xsd
361+
Nabaztag.Tts/appsettings.development.json

Nabaztag.Net.Sample/Program.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,32 @@ static void Main(string[] args)
3232
_nabaztag.EarsEvent += Nabaztag_EarsEvent;
3333
_nabaztag.AsrEvent += Nabaztag_AsrEvent;
3434

35-
SleepAwake();
36-
Tests();
37-
PlayMyOwnFiles();
38-
SetInteractive();
39-
ResetAllEvents();
40-
SubscribeToEvents();
41-
SendInfo();
42-
PlayChoreographyCommand();
43-
PlayAudioChoreoMessage();
44-
ResetAllEvents();
35+
//GetStatistics();
36+
//SleepAwake();
37+
//Tests();
38+
//PlayMyOwnFiles();
39+
//SetInteractive();
40+
//ResetAllEvents();
41+
//SubscribeToEvents();
42+
//SendInfo();
43+
//PlayChoreographyCommand();
44+
//PlayAudioChoreoMessage();
45+
//ResetAllEvents();
46+
}
47+
48+
private static void GetStatistics()
49+
{
50+
var res = _nabaztag.GetStatistics();
51+
Console.WriteLine($"Connections: {res.Connections}");
52+
Console.WriteLine($"Hardware: ");
53+
Console.WriteLine($" Model: {res.Hardware?.Model}");
54+
Console.WriteLine($" Sound Card: {res.Hardware?.SoundCard}");
55+
Console.WriteLine($" Sound Input: {res.Hardware?.SoundInput}");
56+
Console.WriteLine($" Is RFID: {res.Hardware?.IsRfid}");
57+
Console.WriteLine($" Left ear: {res.Hardware?.LeftEarStatus}");
58+
Console.WriteLine($" Right ear: {res.Hardware?.RrightEarStatus}");
59+
Console.WriteLine($"State: {res.State}");
60+
Console.WriteLine($"Uptime: {res.Uptime}");
4561
}
4662

4763
private static void PlayMyOwnFiles()

Nabaztag.Net.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nabaztag.Net.Sample", "Naba
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nabaztag.Net", "Nabaztag.Net\Nabaztag.Net.csproj", "{A5E1158B-9110-4FB0-809B-71C29E792DE3}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nabaztag.Net.Test", "Nabaztag.Net.Test\Nabaztag.Net.Test.csproj", "{F752AE15-CA91-4B9F-9001-B737079028BB}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nabaztag.Net.Test", "Nabaztag.Net.Test\Nabaztag.Net.Test.csproj", "{F752AE15-CA91-4B9F-9001-B737079028BB}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nabaztag.Simulator", "Nabaztag.Simulator\Nabaztag.Simulator.csproj", "{FA2BB76B-CD4F-4B91-99C3-BCBE671DDE7D}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nabaztag.Simulator", "Nabaztag.Simulator\Nabaztag.Simulator.csproj", "{FA2BB76B-CD4F-4B91-99C3-BCBE671DDE7D}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nabaztag.Tts", "Nabaztag.Tts\Nabaztag.Tts.csproj", "{6F220049-045A-4F66-9071-605658BC555E}"
1315
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +35,10 @@ Global
3335
{FA2BB76B-CD4F-4B91-99C3-BCBE671DDE7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{FA2BB76B-CD4F-4B91-99C3-BCBE671DDE7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{FA2BB76B-CD4F-4B91-99C3-BCBE671DDE7D}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{6F220049-045A-4F66-9071-605658BC555E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{6F220049-045A-4F66-9071-605658BC555E}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{6F220049-045A-4F66-9071-605658BC555E}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{6F220049-045A-4F66-9071-605658BC555E}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

Nabaztag.Net/Models/Hardware.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to Laurent Ellerbach under one or more agreements.
2+
// Laurent Ellerbach licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Newtonsoft.Json;
6+
7+
namespace Nabaztag.Net.Models
8+
{
9+
/// <summary>
10+
/// The hardware details
11+
/// </summary>
12+
public class Hardware
13+
{
14+
/// <summary>
15+
/// The model
16+
/// </summary>
17+
[JsonProperty(PropertyName = "model")]
18+
public string Model { get; set; }
19+
/// <summary>
20+
/// The sound card type
21+
/// </summary>
22+
[JsonProperty(PropertyName = "sound_card")]
23+
public string SoundCard { get; set; }
24+
/// <summary>
25+
/// The sound input
26+
/// </summary>
27+
[JsonProperty(PropertyName = "sound_input")]
28+
public bool SoundInput { get; set; }
29+
/// <summary>
30+
/// Is RFID installed
31+
/// </summary>
32+
[JsonProperty(PropertyName = "rfid")]
33+
public bool IsRfid { get; set; }
34+
/// <summary>
35+
/// The status of the left hear
36+
/// </summary>
37+
[JsonProperty(PropertyName = "left_ear_status")]
38+
public string LeftEarStatus { get; set; }
39+
/// <summary>
40+
/// The status of the right hear
41+
/// </summary>
42+
[JsonProperty(PropertyName = "right_ear_status")]
43+
public string RrightEarStatus { get; set; }
44+
}
45+
46+
}

Nabaztag.Net/Models/Paquet.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Converters;
67

78
namespace Nabaztag.Net.Models
89
{
@@ -14,7 +15,14 @@ public class Paquet
1415
/// <summary>
1516
/// The type of paquet, determine the type of the element
1617
/// </summary>
18+
[JsonConverter(typeof(StringEnumConverter))]
1719
[JsonProperty(PropertyName = "type")]
1820
public PaquetType Type { get; set; }
21+
22+
/// <summary>
23+
/// A request id, optional
24+
/// </summary>
25+
[JsonProperty(PropertyName = "request_id", NullValueHandling = NullValueHandling.Ignore)]
26+
public string RequestId { get; set; }
1927
}
2028
}

Nabaztag.Net/Models/PaquetType.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ public enum PaquetType
9696
[JsonProperty(PropertyName = "asr_event")]
9797
AsrEvent,
9898
/// <summary>
99-
/// Asr event
99+
/// Test
100100
/// </summary>
101101
[EnumMember(Value = "test")]
102102
[JsonProperty(PropertyName = "test")]
103-
Test
103+
Test,
104+
/// <summary>
105+
/// statistics of the platform
106+
/// </summary>
107+
[EnumMember(Value = "gestalt")]
108+
[JsonProperty(PropertyName = "gestalt")]
109+
Statistics,
110+
104111
}
105112
}

Nabaztag.Net/Models/Response.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class Response
3333
/// The status
3434
/// </summary>
3535
[JsonConverter(typeof(StringEnumConverter))]
36-
[JsonProperty(PropertyName = "status", Required = Required.Always)]
37-
public Status Status { get; set; }
36+
[JsonProperty(PropertyName = "status")]
37+
public Status? Status { get; set; }
3838

3939
/// <summary>
4040
/// A class of error in case of error
@@ -47,5 +47,28 @@ public class Response
4747
/// </summary>
4848
[JsonProperty(PropertyName = "message", NullValueHandling = NullValueHandling.Ignore)]
4949
public string ErrorMessage { get; set; }
50+
51+
/// <summary>
52+
/// The state
53+
/// </summary>
54+
[JsonProperty(PropertyName = "state", NullValueHandling = NullValueHandling.Ignore)]
55+
public StateType State { get; set; }
56+
57+
/// <summary>
58+
/// Uptime
59+
/// </summary>
60+
[JsonProperty(PropertyName = "uptime", NullValueHandling = NullValueHandling.Ignore)]
61+
public int Uptime { get; set; }
62+
63+
/// <summary>
64+
/// Connections
65+
/// </summary>
66+
[JsonProperty(PropertyName = "connections", NullValueHandling = NullValueHandling.Ignore)]
67+
public int Connections { get; set; }
68+
/// <summary>
69+
/// Connections
70+
/// </summary>
71+
[JsonProperty(PropertyName = "hardware", NullValueHandling = NullValueHandling.Ignore)]
72+
public Hardware Hardware { get; set; }
5073
}
5174
}

Nabaztag.Net/Models/Statistics.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Converters;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace Nabaztag.Net.Models
8+
{
9+
/// <summary>
10+
/// The statistics about the Nabaztag hardware and softare
11+
/// </summary>
12+
public class Statistics
13+
{
14+
/// <summary>
15+
/// The hardware detail
16+
/// </summary>
17+
public Hardware Hardware { get; set; }
18+
19+
/// <summary>
20+
/// The state
21+
/// </summary>
22+
public StateType State { get; set; }
23+
24+
/// <summary>
25+
/// Uptime
26+
/// </summary>
27+
public int Uptime { get; set; }
28+
29+
/// <summary>
30+
/// Connections
31+
/// </summary>
32+
public int Connections { get; set; }
33+
34+
}
35+
}

Nabaztag.Net/Nabaztag.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,22 @@ public class Nabaztag
2929
public delegate void AsrEventHandler(object sender, AsrEvent state);
3030
public event AsrEventHandler AsrEvent;
3131

32+
/// <summary>
33+
/// SStatistics on uptime, hardware, model
34+
/// </summary>
35+
public Statistics Statistics { get; internal set; }
36+
37+
/// <summary>
38+
/// The state of the Nabaztag
39+
/// </summary>
3240
public NabState State { get; internal set; }
3341

3442
public Nabaztag() : this("localhost", DefaultTcpPortEmmit)
3543
{ }
3644

3745
public Nabaztag(string hostName, int tcpPort)
3846
{
47+
Statistics = new Statistics();
3948
_TcpClient = new TcpClient(hostName, tcpPort);
4049
Task.Factory.StartNew(() => ProcessIncoming());
4150
}
@@ -261,6 +270,19 @@ private Response SendMessageProcessResponse(string toSend, Guid reqId, int cance
261270
return _LastRequestId[reqId.ToString()];
262271
}
263272

273+
public Statistics GetStatistics()
274+
{
275+
Paquet paquet = new Paquet() { Type = PaquetType.Statistics };
276+
Guid reqId;
277+
278+
reqId = Guid.NewGuid();
279+
_LastRequestId.Add(reqId.ToString(), null);
280+
paquet.RequestId = reqId.ToString();
281+
282+
var res = SendMessageProcessResponse(JsonConvert.SerializeObject(paquet), reqId, 30);
283+
return Statistics;
284+
}
285+
264286
private void ProcessIncoming()
265287
{
266288
// Listen to tcp
@@ -285,6 +307,7 @@ private void ProcessIncoming()
285307
{
286308
case PaquetType.State:
287309
State = JsonConvert.DeserializeObject<NabState>(result);
310+
Statistics.State = State.State;
288311
StateEvent?.Invoke(this, State);
289312
break;
290313
case PaquetType.EarsEvent:
@@ -298,16 +321,29 @@ private void ProcessIncoming()
298321
break;
299322
case PaquetType.Response:
300323
var response = JsonConvert.DeserializeObject<Response>(result);
301-
if (response.RequestId != null)
324+
if (response.Status == null)
302325
{
303-
_LastRequestId[response.RequestId] = response;
326+
// We had a statistics in there
327+
Statistics.Hardware = response.Hardware;
328+
Statistics.State = response.State;
329+
Statistics.Uptime = response.Uptime;
330+
Statistics.Connections = response.Connections;
304331
}
305332

333+
if (response.RequestId != null)
334+
{
335+
// If the Response.Status is null then it's the answer to the statistics
336+
_LastRequestId[response.RequestId] = response.Status == null ? new Response() { Status = Status.Ok } : response;
337+
}
338+
306339
break;
307340
case PaquetType.AsrEvent:
308341
var asrEvent = JsonConvert.DeserializeObject<AsrEvent>(result);
309342
AsrEvent?.Invoke(this, asrEvent);
310343
break;
344+
case PaquetType.Statistics:
345+
Statistics = JsonConvert.DeserializeObject<Statistics>(result);
346+
break;
311347
default:
312348
break;
313349
}

0 commit comments

Comments
 (0)