How to Disable Automatic Punctuation on Azure Speech To Text Service

PieroFida 0 Reputation points
2024-01-27T11:03:15.2733333+00:00

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

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,069 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,621 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,631 Reputation points Volunteer Moderator
    2024-01-28T07:53:18.2+00:00

    Have you tried the following ? Otherwise I found this old thread : https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/667

    
    
    speechConfig.SetProperty("punctuation", "explicit");
    
    // Continue with your existing setup
    var speechClient = new SpeechRecognizer(speechConfig, audioConfig);
    stopRecognition = new TaskCompletionSource<int>();
    
    
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.