I am debugging with python audio, having a hard time coding audio.
Here I have a line full of audio data, say, [10, 20, 100].
However, the data is stored in a string variable,
data = " "
I want to check the values ββof this string.
Below are the things I tried
Print as int
I tried using 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
Convert to int
int(data[0]) finished with
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 numerically since the string is actually an array of sound wave.
EDIT
All your answers have been really helpful.
The string is actually generated from the microphone, so I believe this is a raw waveform or vibration data. Further, this should be attributed to the audio API document, PortAudio .
Having studied PortAudio, I will find this useful 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; }
This indicates that I can interpret the data as a float