Skip to content

Commit

Permalink
Text segments streaming (#6)
Browse files Browse the repository at this point in the history
* Starting segments streaming

* Works in editor

* Fixed callback il2cpp

* More comments

* Added scrollview to demo

* Fixed non thread safe?

* Microphone demo update
  • Loading branch information
Macoron authored Apr 12, 2023
1 parent c3756cd commit faa387f
Show file tree
Hide file tree
Showing 12 changed files with 1,134 additions and 110 deletions.
471 changes: 451 additions & 20 deletions Assets/Samples/1 - Audio Clip/1 - Audio Clip.unity

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Assets/Samples/1 - Audio Clip/AudioClipDemo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

namespace Whisper.Samples
Expand All @@ -10,19 +11,25 @@ public class AudioClipDemo : MonoBehaviour
public WhisperManager manager;
public AudioClip clip;
public bool echoSound = true;
public bool streamSegments = true;

[Header("UI")]
public Button button;
public Text outputText;
public Text timeText;

private string _buffer;

private void Awake()
{
button.onClick.AddListener(ButtonPressed);
if (streamSegments)
manager.OnNewSegment += OnNewSegmentHandler;
}

public async void ButtonPressed()
{
_buffer = "";
if (echoSound)
AudioSource.PlayClipAtPoint(clip, Vector3.zero);

Expand All @@ -39,6 +46,12 @@ public async void ButtonPressed()
print(text);
outputText.text = text;
}

private void OnNewSegmentHandler(int index, string text)
{
_buffer += text;
outputText.text = _buffer + "...";
}
}
}

Expand Down
Loading

0 comments on commit faa387f

Please sign in to comment.