Playing sound from Database using MediaPlayer C# - c#

I have sound stored in database in byte[] type. I can easily play with SoundPlayer, but not with MediaPlayer. Nice thing about MediaPlayer is I can play from middle of the sound. SoundPlayer doesn't have this feature. Is there way to play sound which stored in database with MediaPlayer(not from the filesystem).
Any help appreciated.

Unfortunately the MediaPlayer class can only Open media from the file system - it's simply a limitation. It's only option is to receive a Uri. However, I would recommend leveraging NAudio. With NAudio you can in fact play, pause, stop, rewind, and more all in memory.

Related

Play sound with reverb effect with NAudio library?

I am using in my C# winForms application great audio library - NAudio. I am playing sounds by the use of WAVE cache and PlayEngine and i have a question:
Is it possible (and if YES: how?) to play sound with reverb effect with NAudio?
NAudio does not include a reverb effect. It does provide access to the raw audio samples, so you can implement your own effect algorithms. Another option might be to see if there is a Reverb MFT installed and pass the audio through (in the same way that the NAudio MFResampler works).
So the short answer is, unfortunately it's not easy to do.

Prevent .NET Speech Recognition from hearing/recognizing computer speakers

I know this is a long shot, and very difficult, maybe even impossible to do. But I'm going to ask it anyway.
Is there any way to keep .NET's SpeechRecognitionEngine (SAPI) from hearing or recognizing the audio coming from computer speakers, without using an external microphone.
An example would be
Playing a YouTube video, or song, and not of the Recognizer
listen to the audio form that video or song Or at least not recognize it as speech
Thanks
In theory if you have an internal audio source like the YouTube video and want to exclude that from things processed by an internal microphone, you can invert the audio signal from that source and use it to cancel out the same sound picked up via the microphone. That is how noise cancelling headphones work. I have no idea whether that is possible with SAPI – Eric J.
While implementing this would take to long for me, this seems like the most do-able and reasonable answer.

Ability to set audio position before playback

While beginnning audio playback, I need the ability to set the position in the audio file from where to begin the playback.
Please guide me with the API's to be used for this functionality.
Until now I have been using SoundEffectInstance for audio playback, but I do not see an option to set the audio playback position in that.
There are many different ways to play audio, see Media for Windows Phone. Without knowing which one you're using, it's a bit difficult to answer the question.
The MediaElement class has a settable property for Position that could serve your purpose.

Playing a ding in Windows 8?

I need to be able to play a "ding" sound in Windows 8 (a kind of beep that fades out gently), similar to what is seen here: http://tonematrix.audiotool.com/
Is it possible to somehow play this given a frequency? Or can I download sound files for this anywhere?
I noticed how the SoundPlayer no longer works, so the old code I used in my desktop program won't work anymore.
If you have a sound file of it, such as an mp3 or wav, use the MediaElement control. There are a few ways of doing this. For example, set the Source property to a URL (Uri class) or call SetSource() then the Play method.
Windows 8 does not include an easy way to generate a tone or pitch (assuming you mean metro/Windows Store apps). If you can generate the bytes needed to play the sound, place them in a buffer, create an IRandomAccessStream for it then pass it to SetSource. You can emulate the fade out by setting the Volume with a Timer.
It would be nice if there was a "fade out" audio effect that could be used with SetAudioEffect but Microsoft does not provide any audio effects at this time.

C# SoundPlayer Question

I'm trying to get one .wav file to play as ambient music though when another sound is played, it halts the ambient music and I've tried doing play-loop and tried the various sync, async , load.
I think I'm missing something here. Thank you in advance.
Check this question on SO and the suggestions made there. The basic problem is that SoundPlayer can only play one sound stream at a time - if you want to play multiple sounds concurrently you need a different solution.
It is possible to use Windows Media Player for the ambient sound, and play another sound with SoundPlayer at the same time:
// example begin
WMPLib.WindowsMediaPlayer mediaPlayer = new WMPLib.WindowsMediaPlayer();
mediaPlayer.URL = "<theAudioFile>";
mediaPlayer.settings.setMode("loop", true);
mediaPlayer.controls.play();
// example end
A reference to Windows Media Player assembly needs to be added to the solution as well.

Categories

Resources