本文介绍了Windows Phone 7中的录音回声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究WP7,
我已经创建了一个录音应用程序.

当我单击记录"按钮时,
执行的代码是-

Hye,

I m working on WP7,
and i have created a audio recording app.

when i click on record button,
the code executed is -

microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

microphone.BufferReady += new EventHandler<eventargs>(microphone_BufferReady);

microphone.Start();</eventargs>



(其中缓冲区是byte [],麦克风是Microsoft.Xna.Framework.Audio.Microphone对象)

现在,当我覆盖此记录时,我将byte []缓冲区清除为



(where buffer is byte[], microphone is Microsoft.Xna.Framework.Audio.Microphone object)

now when i overwrite this recording, i clear the byte[] buffer as

for(int i= 0;i< buffer.Length; i++)
{
    buffer[i] =0;
}



然后再次执行此代码-



and then again this code is executed -

microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

microphone.BufferReady += new EventHandler<eventargs>(microphone_BufferReady);

microphone.Start();</eventargs>



但是在开始任何记录之前,缓冲区会通过一些字节进行初始化.

为什么会发生??
因此,新的录音会追加到上一个录音,在播放时会回声(重复某些部分).



but buffer gets initialized by some bytes, before any recording gets started.

why is it happening.?
due to this, the new recording gets append to the previous one, n it echo while playing (repeat some parts).

thanks in advance.

推荐答案

stream.flush;
and
stream.SetLength(0);



但是回声问题仍然存在.
就像当我的应用程序启动并且我第一次录制时说-
一二三四"并播放录音,
听起来是正确的-一二三四".

现在,当我用五六七八"覆盖它时
播放,录音的某些部分会像-
一样重复播放五六..五六七八..七八"

为什么会发生这种情况.. ??
是因为SoundEffect对象还是麦克风.?

而且,发生了一些奇怪的事情.

如果我第一次启动我的应用并进行记录,
它记录得很好. (如果您覆盖,回声问题仍然存在).

现在,我保存录音并导航到其他页面并执行其他操作..,

然后如果我导航到要记录的页面
并开始记录,它记录了一些内容,因为byte []具有一些值.

但是当我使用SoundEffect对象播放它时,
我什么也听不到.

没有错误或异常.

为什么会这样?

有什么我想念的东西吗,或者是麦克风吗????


预先感谢.



but the echo problem is still there.
its like when my applications starts and i record for the first time say-
"one two three four" and play the recording,
it sounds correct as- "one two three four".

now when i overwrite it by -"five six seven eight"
and play it, some of the parts of the recording gets repeated like-
"five six.. five six seven eight.. seven eight"

why this happens..??
is it because the SoundEffect object or the Microphone.?

also, there is something strange happening.

if i starts my app and record for the first time,
it records well. (echo problem is still there if u overwrite).

now i save the recording and navigate to some other page and perform some other stuffs..,

and then if i navigate to the page for recording
and starts recording, it records something, as the byte[] have some values.

but when i play it using the SoundEffect object,
there is nothing i can hear.

there is no error or exception.

why this happens?

is there something i m missing, or is it something with the microphone.???


thanks in advance.


private void record()
        {
            counter = 1;
            Microphone microphone = Microphone.Default;

            TimeSpan tt = new TimeSpan();
            tt = TimeSpan.FromMilliseconds(1000);
            microphone.BufferDuration = new TimeSpan(0, 0, 1);
            microphone.BufferDuration = tt;

            buffer = null;
            buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
            stream.SetLength(0);

            microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
            microphone.Start();
        }



        void microphone_BufferReady(object sender, EventArgs e)
        {
            microphone.GetData(buffer);
            stream.Write(buffer, 0, buffer.Length);
        }



现在,当我点击录制"按钮时,将调用



Now when i tap on the record button the method

record()

方法,并且
每1秒钟调用一次Mike_BufferReady.

现在,如果我再次点击录音"按钮并覆盖我以前的录音(我在同一页面上)
每2秒调用一次麦克风_BufferReady.

如果我第三次点击,将是3秒,依此类推.

可以通过在麦克风_BufferReady中取消计数器并将其显示在文本块中来轻松地注意到它.

我不明白为什么会这样.


is called and
microphone_BufferReady is called in every 1 second.

Now, if i again tap on record button and overwrite my previous recording (i m on the same page)
the microphone_BufferReady is called in every 2 second.

if i tap third time it will be 3 sec and so on.

it can be easily noticed by increamenting a counter in microphone_BufferReady and display it in a textblock.

i m not getting why this is happening.?


thanks in advance.



这篇关于Windows Phone 7中的录音回声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 16:36