LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

16进制文本转成WAV

dear labviewer,

 

我有一段16进制文本,如何通过labview转成WAV????

 

 

 

 

0 Kudos
Message 1 of 15
(997 Views)

深 (Bit depth):32BIT

采样率:48K

0 Kudos
Message 2 of 15
(995 Views)

Hexadecimal text is just a log sequence of bytes and can be anything.

 

A wav file is an audio file that is also a sequence of bytes, but has known structure as defined in the audio format standard.

 

In order to correctly parse the hexadecimal string, you need to know the structure. Do you? What was used to generate it?

 

 

0 Kudos
Message 3 of 15
(947 Views)

hi brother,

I have a python script that works on converting the hex text i sent to wav, but I don’t know python. Can you help look into the code and let me know if labview can also do it? Thanks

 

 

import serial
import binascii as ba
import wave
import os
import time
from time import sleep
#from command import testcommandodelist, commandresultlist
import struct
import soundfile as sf
import numpy as np
import sys

 

 

def audio_dump_to_wav_3Mics_32bit(path,new_audio_path,wav_name):
binData = bytearray()
hexfile = open(path,encoding='utf-8')
#print(hexfile)
for textLine in hexfile.readlines():
binFile = []
#print(textLine)
textLine = textLine.upper().strip()
textline = textLine.encode('utf-8','ignore').decode('utf-8')
if (textLine[0] != ':'):continue
textLine = textLine[1:]
#print(textLine)
textLine = textLine.replace('0X', '').replace(',', '').replace(' ', '')
binBytes = ba.unhexlify(textLine)
#print(binBytes)
if binFile: binFile.write(binBytes)
binData += binBytes
endianness = sys.byteorder
crc32 = ba.crc32(binData) & 0xFFFFFFFF
numBytes = len(binData)
print('%d bytes, CRC32: 0x%08X' % (numBytes, crc32))
print(' ')
numSamples = numBytes // struct.calcsize('>f')
dataFormat = ('<%df' % numSamples) if endianness == 'little' else ('>%df' % numSamples)
audio = np.array(struct.unpack(dataFormat, binData))
audio = audio.reshape(int(len(audio)/1),1)
TOP_Data = audio[:,0]
#Top_data = audio[:,0]
#Error_data = audio[:,2]
sf.write(new_audio_path + wav_name +'.wav',TOP_Data,48000,subtype='PCM_32')
#sf.write(new_audio_path + wav_name +'_'+'32bit.wav',Top_data,48000,subtype='PCM_32')
#sf.write(new_audio_path + wav_name +'_'+'Error_32bit.wav',Error_data,16000,subtype='PCM_32')
print("audio dump to wav 黑化肥发灰 灰化肥发黑 !!!")

datapath = '/Users/h3637_h716454/Desktop/py/' # save here
fpmic = datapath + '/'
try:
os.makedirs(fpmic)
except OSError:
print('File Exists')
fp1 = fpmic + '1.txt'
wav_name='1'
audio_dump_to_wav_3Mics_32bit(fp1,fpmic,wav_name)

0 Kudos
Message 4 of 15
(911 Views)

搞定没,老铁 ?

Learning from other people
0 Kudos
Message 5 of 15
(891 Views)

LabVIEW is a full featured programming language and can do anything! Anything!!!

 

Is there a documentation for the incoming data?

 

Sorry, I don't use or read Python. Maybe you could use the Python node that is available in newer LabVIEW versions?

0 Kudos
Message 6 of 15
(878 Views)

没呢 你也要做这个?

0 Kudos
Message 7 of 15
(870 Views)
0 Kudos
Message 8 of 15
(860 Views)

Yes, labview is powerful and perceptual for measurement and automation.

Python is also popular in these years, and work well in both windows and linux OS.

Thanks.

Learning from other people
0 Kudos
Message 9 of 15
(830 Views)

This is raw data, and it is mic recording data( send command to let microhone on tws earbud to record then send command to get the recording data like attachment )

0 Kudos
Message 10 of 15
(751 Views)