// Generate audioframes for the audiograph unsafe private AudioFrame GenerateAudioData(uint samples) { // Buffer size is (number of samples) * (size of each sample) // We choose to generate single channel (mono) audio. For multi-channel, multiply by number of channels uint bufferSize = samples * frameInputNode.EncodingProperties.BitsPerSample; AudioFrame frame = new Windows.Media.AudioFrame(bufferSize); using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.Write)) using (IMemoryBufferReference reference = buffer.CreateReference()) { byte* dataInBytes; uint capacityInBytes; float* dataInFloat; // Get the buffer from the AudioFrame ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacityInBytes); // Cast to float since the data we are generating is float dataInFloat = (float*)dataInBytes; float amplitude = 0.3f; int sampleRate = (int)audioGraph.EncodingProperties.SampleRate; double sampleIncrement = ((pitch*2*Math.PI)/sampleRate); // Generate a 1kHz sine wave and populate the values in the memory buffer for (int i = 0; i < samples; i++) { double sinValue = amplitude * Math.Sin(i*sampleIncrement); dataInFloat[i] = (float)sinValue; } } return frame; }
private void SendToSpeechTranslate(Windows.Media.AudioFrame frame) { this.viewModel.SpeechHelper.SendAudioFrame(frame); }
private void SendAudioOut(Windows.Media.AudioFrame frame) { this.textToSpeechOutputNode.AddFrame(frame); }