Skip to content

Commit 5e78128

Browse files
committed
feat: sample UI updates
1 parent 86148f9 commit 5e78128

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Samples~/Whisper/Whisper Sample.unity

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ RectTransform:
338338
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
339339
m_AnchorMin: {x: 0.5, y: 0}
340340
m_AnchorMax: {x: 0.5, y: 0}
341-
m_AnchoredPosition: {x: 0, y: 20}
341+
m_AnchoredPosition: {x: 0, y: 100}
342342
m_SizeDelta: {x: 300, y: 30}
343343
m_Pivot: {x: 0.5, y: 0}
344344
--- !u!114 &127668736
@@ -617,12 +617,12 @@ MonoBehaviour:
617617
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
618618
m_Name:
619619
m_EditorClassIdentifier:
620-
m_UiScaleMode: 0
620+
m_UiScaleMode: 1
621621
m_ReferencePixelsPerUnit: 100
622622
m_ScaleFactor: 1
623623
m_ReferenceResolution: {x: 800, y: 600}
624624
m_ScreenMatchMode: 0
625-
m_MatchWidthOrHeight: 0
625+
m_MatchWidthOrHeight: 0.5
626626
m_PhysicalUnit: 3
627627
m_FallbackScreenDPI: 96
628628
m_DefaultSpriteDPI: 96
@@ -811,7 +811,7 @@ RectTransform:
811811
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
812812
m_AnchorMin: {x: 0.5, y: 0}
813813
m_AnchorMax: {x: 0.5, y: 0}
814-
m_AnchoredPosition: {x: 0, y: 300}
814+
m_AnchoredPosition: {x: 0, y: 380}
815815
m_SizeDelta: {x: 300, y: 30}
816816
m_Pivot: {x: 0.5, y: 0}
817817
--- !u!114 &806708132
@@ -1388,7 +1388,7 @@ RectTransform:
13881388
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
13891389
m_AnchorMin: {x: 0.5, y: 0}
13901390
m_AnchorMax: {x: 0.5, y: 0}
1391-
m_AnchoredPosition: {x: 0, y: 60}
1391+
m_AnchoredPosition: {x: 0, y: 140}
13921392
m_SizeDelta: {x: 300, y: 200}
13931393
m_Pivot: {x: 0.5, y: 0}
13941394
--- !u!114 &1555334134
@@ -1666,7 +1666,7 @@ RectTransform:
16661666
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
16671667
m_AnchorMin: {x: 0.5, y: 0}
16681668
m_AnchorMax: {x: 0.5, y: 0}
1669-
m_AnchoredPosition: {x: 0, y: 270}
1669+
m_AnchoredPosition: {x: 0, y: 350}
16701670
m_SizeDelta: {x: 300, y: 20}
16711671
m_Pivot: {x: 0.5, y: 0}
16721672
--- !u!114 &1670234776

Samples~/Whisper/Whisper.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,30 @@ private void Start()
2626
dropdown.options.Add(new Dropdown.OptionData(device));
2727
}
2828
recordButton.onClick.AddListener(StartRecording);
29+
dropdown.onValueChanged.AddListener(ChangeMicrophone);
30+
31+
var index = PlayerPrefs.GetInt("user-mic-device-index");
32+
dropdown.SetValueWithoutNotify(index);
2933
}
3034

35+
private void ChangeMicrophone(int index)
36+
{
37+
PlayerPrefs.SetInt("user-mic-device-index", index);
38+
}
39+
3140
private void StartRecording()
3241
{
3342
isRecording = true;
3443
recordButton.enabled = false;
35-
36-
clip = Microphone.Start(dropdown.options[dropdown.value].text, false, duration, 44100);
44+
45+
var index = PlayerPrefs.GetInt("user-mic-device-index");
46+
clip = Microphone.Start(dropdown.options[index].text, false, duration, 44100);
3747
}
3848

3949
private async void EndRecording()
4050
{
4151
message.text = "Transcripting...";
4252

43-
isRecording = false;
4453
Microphone.End(null);
4554
byte[] data = SaveWav.Save(fileName, clip);
4655

@@ -53,7 +62,9 @@ private async void EndRecording()
5362
};
5463
var res = await openai.CreateAudioTranscription(req);
5564

65+
progressBar.fillAmount = 0;
5666
message.text = res.Text;
67+
recordButton.enabled = true;
5768
}
5869

5970
private void Update()
@@ -65,6 +76,7 @@ private void Update()
6576

6677
if (time >= duration)
6778
{
79+
time = 0;
6880
isRecording = false;
6981
EndRecording();
7082
}

0 commit comments

Comments
 (0)