#python #ios #debugging #kivy
Вопрос:
[Правка]: Я думаю, что решение приведенного ниже вопроса включает в себя правильную настройку одного из аспектов аудиосистемы iOS во время выполнения, но я не уверен, что это будет связано или как это сделать. Любая помощь будет очень признательна!
[Исходный вопрос]: Похоже, возникла проблема с модулем audiostream, из-за которой mic.poll()
функция обратного вызова не вызывается get_input(callback = callbackFunction, rate = rate, buffersize = buffersize)
после использования динамика на моем iPhone для вывода звука.
Мой код отлично работает при записи звука без каких-либо предыдущих действий, но если я использую модуль аудиовыхода audiostream или модуль SoundLoader Kivy и попытаюсь снова записать звук с помощью get_input
, то mic.poll()
произойдет сбой, и данные буфера не будут отправлены в функцию обратного get_input
вызова . Я полагаю, что эта проблема связана с тем, как телефон перестраивается при использовании динамиков, так как, если я не выводю аудио, я могу записывать аудио с помощью аудиопотока бесконечное количество раз.
Вот мой код для записи звука:
def __init__(self, **kw):
super().__init__(**kw)
self.samples_per_second = 60 # variables which stores the number of audio samples recorded per second
self.audioData = [] # creates a list to store the audio bytes recorded
import sys
importlib.reload(sys.modules['audiostream']) # reloads the audiostream module - thought this might solve the problem; it doesn't!!
self.mic = get_input(callback=self.micCallback, rate=8000, source='default', buffersize=2048) # initialises the method get_input from the module 'audiostream' with the properties required to ensure the audio is recorded correctly
def micCallback(self, buffer):
# method which is called by the method 'get_input' to store recorded audio data (each buffer of audio samples)
self.audioData.append(buffer) # appends each buffer (chunk of audio data) to variable 'self.audioData'
def start(self):
# method which begins the process of recording the audio data
self.mic.start() # starts the method 'self.mic' recording audio data
Clock.schedule_interval(self.readChunk, 1 / self.samples_per_second) # calls the method 'self.readChunk' to read and store each audio buffer (2048 samples) 60 times per second
def readChunk(self, sampleRate):
# method which coordinates the reading and storing of the bytes from each buffer of audio data (which is a chunk of 2048 samples)
self.mic.poll() # calls 'get_input(callback=self.mic_callback, source='mic', buffersize=2048)' to read the byte content. This byte content is then dispatched to the callback method 'self.micCallback'
def stop(self):
# method which terminates and saves the audio recording when the recording has been successful
Clock.unschedule(self.readChunk) # un-schedules the Clock's rythmic execution of the 'self.readChunk' callback
self.mic.stop() # stops recording audio
return self.audioData
Вот код, который я использовал для вывода звука после использования вышеуказанного кода для записи звука:
messageFile_voice = SoundLoader.load("filename.wav")
messageFile_voice.play()