Updated on 2022-02-22 GMT+08:00
Example - Input
The following is an example of the audio input module:
#! /usr/bin/python3.7 import hilens import wave def run(): # Construct a local audio file collector and save the decoded data to a WAV file. cap = hilens.AudioCapture("\tmp\test.aac") # Construct a local microphone collector. cap2 = hilens.AudioCapture(sample_rate=hilens.AUDIO_SAMPLE_RATE_16000, bit_width=hilens.AUDIO_BIT_WIDTH_16, nSamples=1000, sound_mode=hilens.AUDIO_SOUND_MODE_MONO) wav = wave.open("test.wav", "wb") wav.setnchannels(2) # Set the number of channels to 2. wav.setsampwidth(2) # Set the sampling rate to 16 bits. wav.setframerate(44100) # Set the sampling rate. for i in range(100): # Read 500 frames of data and write the data to a file (about 12s). data = cap.read(5) wav.writeframes(data.tobytes()) wav.close() # The test.wav audio file is generated in the current directory and can be opened using a common player. if __name__ == '__main__': hilens.init("hello") run() hilens.terminate()
Parent topic: Audio Input Module
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot