如何打印一个充满&QUOT字符串值;乱问号" [英] How to print values of a string full of "chaos question marks"

查看:208
本文介绍了如何打印一个充满&QUOT字符串值;乱问号"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与蟒蛇音响调试,有一个很难与音频编码。

I'm debugging with python audio, having a hard time with the audio coding.

在这里,我有一个字符串全音频数据,比方说,[10,20,100]。

Here I have a string full of audio data, say, [10, 20, 100].

然而该数据存储在一个字符串变量,

However the data is stored in a string variable,

data = "����������������"

我要检查这个字符串的值。

I want to inspect the values of this string.

下面是我试过

我试图用打印%i的%的数据[0]
结束了

I tried to use print "%i" % data[0] ended up with

 Traceback (most recent call last):
   File "wire.py", line 28, in <module>
     print "%i" % data[i]
 TypeError: %d format: a number is required, not str

转换成int

INT(数据[0])结束了

Traceback (most recent call last):
  File "wire.py", line 27, in <module>
    print int(data[0])
ValueError: invalid literal for int() with base 10: '\xd1'

对此有何想法?我要打印的字符串中的数字的方式,因为字符串其实是声波的数组。

Any idea on this? I want to print the string in a numerical way since the string is actually an array of sound wave.

您所有的答案竟然是真的很有帮助。

All your answers turned out to be really helpful.

该字符串实际上是从麦克风产生的,所以我认为这是原始波形,或振动数据。而且这应该交由音频API文档, PortAudio

The string is actually generated from the microphone so I believe it to be raw wave form, or vibration data. Further this should be referred to the audio API document, PortAudio.

寻找到PortAudio之后,我觉得这是有帮助的例子。

After looking into PortAudio, I find this helpful example.

** This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
static int patestCallback( const void *inputBuffer, void *outputBuffer,
                            unsigned long framesPerBuffer,
                            const PaStreamCallbackTimeInfo* timeInfo,
                            PaStreamCallbackFlags statusFlags,
                            void *userData )
{
    paTestData *data = (paTestData*)userData;
    float *out = (float*)outputBuffer;
    unsigned long i;

    (void) timeInfo; /* Prevent unused variable warnings. */
    (void) statusFlags;
    (void) inputBuffer;

    for( i=0; i<framesPerBuffer; i++ )
    {
        *out++ = data->sine[data->left_phase];  /* left */
        *out++ = data->sine[data->right_phase];  /* right */
        data->left_phase += 1;
        if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
        data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
        if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
    }

    return paContinue;
}

这表明,有一些方法,我可以跨preT的数据作为浮动

This indicates that there is some way that I can interpret the data as float

推荐答案

要清楚,你的音频数据的字节字符串。字节串是存储在音频文件中的一个字节重新presentation。你不会简单地能够将这些字节转换成有意义的值转换不知道什么是二进制第一。

To be clear, your audio data is a byte string. The byte string is a representation of the bytes stored in the audio file. You are not going to simply be able to convert those bytes into meaningful values without knowing what is in the binary first.

作为一个例子,MP3的规范指出,每一个MP3包含头帧(这里描述:的http:// en.wikipedia.org/wiki/MP3 )。要读取头,你要么需要使用像位串,或如果你感觉很舒服做位操作自己,那么你只需要解压的一个整数(4字节),并做一些数学计算出的32个独立位的值。

As an example, the mp3 specification says that each mp3 contains header frames (described here: http://en.wikipedia.org/wiki/MP3). To read the header you would either need to use something like bitstring, or if you feel comfortable doing the bitwise manipulation yourself then you would just need to unpack an integer (4 bytes) and do some math to figure out the values of the 32 individual bits.

这真的一切都取决于你想读什么,以及如何生成的数据。如果你有全半角数字,那么结构将竭诚为您服务好。

It really all depends on what you are trying to read, and how the data was generated. If you have whole byte numbers, then struct will serve you well.

这篇关于如何打印一个充满&QUOT字符串值;乱问号&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆