Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Readded experimental Windows Speech API using WebSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
demonixis committed Dec 21, 2022
1 parent a0af423 commit 373c1e6
Show file tree
Hide file tree
Showing 31 changed files with 724 additions and 353 deletions.
55 changes: 0 additions & 55 deletions .vscode/settings.json

This file was deleted.

136 changes: 136 additions & 0 deletions Arduino/InMoovServos/InMoovServos-Bluetooth-BETA.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include <Servo.h>
#include <SoftwareSerial.h>

const int PinStart = 2;
const int PinEnd = 53;
#if defined(ARDUINO_AVR_MEGA2560)
const int BoardPinEnd = PinEnd;
#else
const int BoardPinEnd = 13;
#endif
const int BufferLength = BoardPinEnd - PinStart;
const int ServoCount = PinEnd - PinStart;
const int ServoMin = 0;
const int ServoNeutral = 90;
const int ServoMax = 180;
const int DefaultBaudRate = 9600;
const int MaxBufferSize = 63;

// The trame is
// Servo 0 (Pin2) => Value [0; 180], Disable if value is upper to ServoMax
// byteArray[index] => Value [0; 180]

// Servos
Servo servos[ServoCount];
int values[ServoCount];
int servoActivation[ServoCount];
int lastServoActivation[ServoCount];

// Bluetooth
const byte rxBT = 2;
const byte txBT = 3;
SoftwareSerial BTSerial(rxBT, txBT);

// Prototypes
void CheckSerialData();
void CheckBluetoothData();
void ApplyServoValues();

void setup() {
Serial.begin(DefaultBaudRate);
BTSerial.begin(DefaultBaudRate);

for (int i = 0; i < ServoCount; i++) {
values[i] = ServoNeutral; // Neutral
servoActivation[i] = 0;
lastServoActivation[i] = 0;
}
}

void loop() {
// Handle USB connection (PC)
if (Serial.available()) {
CheckSerialData();
ApplyServoValues();
}

// Handle Bluetooth connection (Everything)
if (BTSerial.available()) {
CheckBluetoothSerial();
ApplyServoValues();
}
}

void CheckSerialData() {
// Read data from the Unity App, see the header for the trame
int dataCount = Serial.available();

if (dataCount > 0) {
Serial.println(dataCount);
}

if (dataCount != ServoCount) {
// Flush the buffer if full.
if (dataCount == MaxBufferSize) {
while (Serial.available()) {
Serial.read();
}
}

// Return while it doesn't have the expected size.
return;
}

int i = 0;
while (Serial.available() > 0) {
values[i] = Serial.read();
servoActivation[i] = values[i] <= ServoMax ? 1 : 0;
i++;
}
}

void CheckBluetoothSerial() {
// Read data from the Unity App, see the header for the trame
int dataCount = BTSerial.available();

if (dataCount > 0) {
BTSerial.println(dataCount);
}

if (dataCount != ServoCount) {
// Flush the buffer if full.
if (dataCount == MaxBufferSize) {
while (BTSerial.available()) {
BTSerial.read();
}
}

// Return while it doesn't have the expected size.
return;
}

int i = 0;
while (BTSerial.available() > 0) {
values[i] = BTSerial.read();
servoActivation[i] = values[i] <= ServoMax ? 1 : 0;
i++;
}
}

void ApplyServoValues() {
// Apply values to the servos
for (int i = 0; i < BufferLength; i++) {
// Check if we need to enable or disable the servo
if (servoActivation[i] != lastServoActivation[i]) {
if (servoActivation[i] > 0) {
servos[i].attach(i + PinStart);
} else {
servos[i].detach();
}
lastServoActivation[i] = servoActivation[i];
}

// Apply the value if enabled.
servos[i].write(values[i]);
}
}
Binary file removed Assets/Plugins/Windows/TTSDLL.dll
Binary file not shown.
71 changes: 0 additions & 71 deletions Assets/Plugins/Windows/TTSDLL.dll.meta

This file was deleted.

92 changes: 91 additions & 1 deletion Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,50 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &92669364
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 92669365}
- component: {fileID: 92669366}
m_Layer: 0
m_Name: Microsoft.Speech WebSocket (Windows Only)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &92669365
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 92669364}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1345134534}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &92669366
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 92669364}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5ac44cb54645d974d939d08f8148feff, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &101045438
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1060,6 +1104,50 @@ Transform:
m_Father: {fileID: 1933734190}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &835129784
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 835129785}
- component: {fileID: 835129786}
m_Layer: 0
m_Name: Microsoft.Speech WebSocket (Windows Only)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &835129785
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 835129784}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2011295491}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &835129786
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 835129784}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a728a6b6f9b2a864f8024a0ef96ad6b7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &921530816
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1693,7 +1781,7 @@ MonoBehaviour:
_jawOpenTime: 0.15
_jawCloseTime: 0.1
_jawAmplitude: 20
_wordsPerMinute: 40
_jawNeutralOffset: 10
--- !u!114 &1281199286
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1848,6 +1936,7 @@ Transform:
m_Children:
- {fileID: 115404854}
- {fileID: 53364776}
- {fileID: 92669365}
m_Father: {fileID: 996090396}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -2640,6 +2729,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1367671925}
- {fileID: 835129785}
- {fileID: 1033768235}
- {fileID: 348550591}
m_Father: {fileID: 996090396}
Expand Down
Loading

0 comments on commit 373c1e6

Please sign in to comment.