Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
24-SP-Poglitsch-Giner-GenAgents
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giner, Aaron
24-SP-Poglitsch-Giner-GenAgents
Commits
8c4f0a3d
Commit
8c4f0a3d
authored
7 months ago
by
Giner, Aaron
Browse files
Options
Downloads
Patches
Plain Diff
removed old files
parent
d89e8a48
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unity/Assets/Scripts/SpeechRecognitionTest.cs
+0
-99
0 additions, 99 deletions
unity/Assets/Scripts/SpeechRecognitionTest.cs
unity/Assets/Scripts/SpeechRecognitionTest.cs.meta
+0
-11
0 additions, 11 deletions
unity/Assets/Scripts/SpeechRecognitionTest.cs.meta
with
0 additions
and
110 deletions
unity/Assets/Scripts/SpeechRecognitionTest.cs
deleted
100644 → 0
+
0
−
99
View file @
d89e8a48
using
System.IO
;
using
HuggingFace.API
;
using
TMPro
;
using
UnityEngine
;
using
UnityEngine.UI
;
// https://huggingface.co/blog/unity-asr
public
class
SpeechRecognitionTest
:
MonoBehaviour
{
[
SerializeField
]
private
Button
startButton
;
[
SerializeField
]
private
Button
stopButton
;
[
SerializeField
]
private
TextMeshProUGUI
text
;
private
AudioClip
clip
;
private
byte
[]
bytes
;
private
bool
recording
;
private
void
Start
()
{
startButton
.
onClick
.
AddListener
(
StartRecording
);
stopButton
.
onClick
.
AddListener
(
StopRecording
);
stopButton
.
interactable
=
false
;
}
private
void
Update
()
{
if
(
recording
&&
Microphone
.
GetPosition
(
null
)
>=
clip
.
samples
)
{
StopRecording
();
}
}
private
void
StartRecording
()
{
text
.
color
=
Color
.
white
;
text
.
text
=
"Recording..."
;
startButton
.
interactable
=
false
;
stopButton
.
interactable
=
true
;
clip
=
Microphone
.
Start
(
null
,
false
,
10
,
44100
);
recording
=
true
;
}
private
void
StopRecording
()
{
var
position
=
Microphone
.
GetPosition
(
null
);
Microphone
.
End
(
null
);
var
samples
=
new
float
[
position
*
clip
.
channels
];
clip
.
GetData
(
samples
,
0
);
bytes
=
EncodeAsWAV
(
samples
,
clip
.
frequency
,
clip
.
channels
);
recording
=
false
;
SendRecording
();
}
private
void
SendRecording
()
{
text
.
color
=
Color
.
yellow
;
text
.
text
=
"Sending..."
;
stopButton
.
interactable
=
false
;
HuggingFaceAPI
.
AutomaticSpeechRecognition
(
bytes
,
response
=>
{
text
.
color
=
Color
.
white
;
text
.
text
=
response
;
startButton
.
interactable
=
true
;
},
error
=>
{
text
.
color
=
Color
.
red
;
text
.
text
=
error
;
startButton
.
interactable
=
true
;
});
}
private
byte
[]
EncodeAsWAV
(
float
[]
samples
,
int
frequency
,
int
channels
)
{
using
(
var
memoryStream
=
new
MemoryStream
(
44
+
samples
.
Length
*
2
))
{
using
(
var
writer
=
new
BinaryWriter
(
memoryStream
))
{
writer
.
Write
(
"RIFF"
.
ToCharArray
());
writer
.
Write
(
36
+
samples
.
Length
*
2
);
writer
.
Write
(
"WAVE"
.
ToCharArray
());
writer
.
Write
(
"fmt "
.
ToCharArray
());
writer
.
Write
(
16
);
writer
.
Write
((
ushort
)
1
);
writer
.
Write
((
ushort
)
channels
);
writer
.
Write
(
frequency
);
writer
.
Write
(
frequency
*
channels
*
2
);
writer
.
Write
((
ushort
)(
channels
*
2
));
writer
.
Write
((
ushort
)
16
);
writer
.
Write
(
"data"
.
ToCharArray
());
writer
.
Write
(
samples
.
Length
*
2
);
foreach
(
var
sample
in
samples
)
{
writer
.
Write
((
short
)(
sample
*
short
.
MaxValue
));
}
}
return
memoryStream
.
ToArray
();
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
unity/Assets/Scripts/SpeechRecognitionTest.cs.meta
deleted
100644 → 0
+
0
−
11
View file @
d89e8a48
fileFormatVersion: 2
guid: 27169f9dd1c9fa44aa343d1e008e638b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment