I'm using Azure STT service, and My goal is to disable the Automatic Punctuation from regognized results.
I'm using continuous Recognition from continuous Streaming source with following code:
//Initialize the Stream Handling PullAudioInputStreamCallback derived class
var audioStream = new VoiceAudioStream();
// Initialize with the format required by the Speech service
var audioFormat = AudioStreamFormat.GetWaveFormatPCM(8000, 16, 1);
// Configure speech SDK to work with the audio stream in right format.
var audioConfig = AudioConfig.FromStreamInput(audioStream, audioFormat);
// Get credentials and region from client's message.
var speechConfig = SpeechConfig.FromSubscription(key, region);
speechConfig.SpeechRecognitionLanguage = "it-IT";
speechConfig.EnableDictation(); //<- Dictation Mode
// With all the info at hand, finally create the SpeechRecognizer instance.
var speechClient = new SpeechRecognizer(speechConfig, audioConfig);
stopRecognition = new TaskCompletionSource<int>();
here the PullAudioInputStreamCallback derived class I'm using:
public class VoiceAudioStream : PullAudioInputStreamCallback
{
private readonly EchoStream _dataStream = new();
private ManualResetEvent _waitForEmptyDataStream = null;
public override int Read(byte[] dataBuffer, uint size)
{
if (_waitForEmptyDataStream != null && !_dataStream.DataAvailable)
{
_waitForEmptyDataStream.Set();
return 0;
}
return _dataStream.Read(dataBuffer, 0, dataBuffer.Length);
}
public void Write(byte[] buffer, int offset, int count)
{
_dataStream.Write(buffer, offset, count);
}
public override void Close()
{
if (_dataStream.DataAvailable)
{
_waitForEmptyDataStream = new ManualResetEvent(false);
_waitForEmptyDataStream.WaitOne();
}
_waitForEmptyDataStream.Close();
_dataStream.Dispose();
base.Close();
}
}
Here the eco stream class code:
public class EchoStream : MemoryStream
{
private readonly ManualResetEvent _DataReady = new(false);
private readonly ConcurrentQueue<byte[]> _Buffers = new();
public bool DataAvailable { get { return !_Buffers.IsEmpty; } }
public override void Write(byte[] buffer, int offset, int count)
{
_Buffers.Enqueue(buffer.Take(count).ToArray()); // add new data to buffer
_DataReady.Set(); // allow waiting reader to proceed
}
public override int Read(byte[] buffer, int offset, int count)
{
_DataReady.WaitOne(); // block until there's something new to read
if (!_Buffers.TryDequeue(out byte[] lBuffer)) // try to read
{
_DataReady.Reset();
return -1;
}
if (!DataAvailable)
_DataReady.Reset();
Array.Copy(lBuffer, buffer, lBuffer.Length);
return lBuffer.Length;
}
}
Recognising works fine except Automatic punctuation, that still works despite being enabled "Dictation" .
So some suggestion how to Disable Automatic puntuation?
Thank you