Paul Bird
commited on
Upload RunWhisper.cs
Browse files- RunWhisper.cs +9 -7
RunWhisper.cs
CHANGED
|
@@ -100,9 +100,17 @@ public class RunWhisper : MonoBehaviour
|
|
| 100 |
if(audioClip.frequency != 16000)
|
| 101 |
{
|
| 102 |
Debug.Log($"The audio clip should have frequency 16kHz. It has frequency {audioClip.frequency / 1000f}kHz");
|
|
|
|
| 103 |
}
|
| 104 |
|
| 105 |
numSamples = audioClip.samples;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
data = new float[numSamples];
|
| 107 |
audioClip.GetData(data, 0);
|
| 108 |
}
|
|
@@ -122,11 +130,6 @@ public class RunWhisper : MonoBehaviour
|
|
| 122 |
void EncodeAudio()
|
| 123 |
{
|
| 124 |
using var input = new TensorFloat(new TensorShape(1, numSamples), data);
|
| 125 |
-
if (numSamples > maxSamples)
|
| 126 |
-
{
|
| 127 |
-
Debug.Log("The AudioClip is too long.");
|
| 128 |
-
return;
|
| 129 |
-
}
|
| 130 |
|
| 131 |
// Pad out to 30 seconds at 16khz if necessary
|
| 132 |
using var input30seconds = ops.Pad(input, new int[] { 0, 0, 0, maxSamples - numSamples });
|
|
@@ -160,8 +163,7 @@ public class RunWhisper : MonoBehaviour
|
|
| 160 |
|
| 161 |
int ID = tokensPredictions[currentToken];
|
| 162 |
|
| 163 |
-
currentToken
|
| 164 |
-
outputTokens[currentToken] = ID;
|
| 165 |
|
| 166 |
if (ID == END_OF_TEXT)
|
| 167 |
{
|
|
|
|
| 100 |
if(audioClip.frequency != 16000)
|
| 101 |
{
|
| 102 |
Debug.Log($"The audio clip should have frequency 16kHz. It has frequency {audioClip.frequency / 1000f}kHz");
|
| 103 |
+
return;
|
| 104 |
}
|
| 105 |
|
| 106 |
numSamples = audioClip.samples;
|
| 107 |
+
|
| 108 |
+
if (numSamples > maxSamples)
|
| 109 |
+
{
|
| 110 |
+
Debug.Log($"The AudioClip is too long. It must be less than 30 seconds. This clip is {numSamples/ audioClip.frequency} seconds.");
|
| 111 |
+
return;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
data = new float[numSamples];
|
| 115 |
audioClip.GetData(data, 0);
|
| 116 |
}
|
|
|
|
| 130 |
void EncodeAudio()
|
| 131 |
{
|
| 132 |
using var input = new TensorFloat(new TensorShape(1, numSamples), data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
// Pad out to 30 seconds at 16khz if necessary
|
| 135 |
using var input30seconds = ops.Pad(input, new int[] { 0, 0, 0, maxSamples - numSamples });
|
|
|
|
| 163 |
|
| 164 |
int ID = tokensPredictions[currentToken];
|
| 165 |
|
| 166 |
+
outputTokens[++currentToken] = ID;
|
|
|
|
| 167 |
|
| 168 |
if (ID == END_OF_TEXT)
|
| 169 |
{
|