bugfix
This commit is contained in:
parent
015ea2f23c
commit
1d67f0cbaf
@ -1,44 +0,0 @@
|
||||
|
||||
import tempfile
|
||||
import pyaudio
|
||||
import wave
|
||||
from kivy.event import EventDispatcher
|
||||
from kivy.properties import NumericProperty
|
||||
from kivyblocks.baseWidget import HBox
|
||||
from kviyblocks.micphone import Micphone
|
||||
|
||||
class AudioRecorder(EventDispatcher):
|
||||
fs = NumericProperty(None)
|
||||
filename = StringProperty(None)
|
||||
voice_src = OjbectProperty(None)
|
||||
def __init__(self, **kw):
|
||||
super(AudioRecorder, self).__init__(**kw)
|
||||
self.saving = False
|
||||
if not self.filename:
|
||||
self.mk_temp_file()
|
||||
|
||||
def mk_temp_file(self):
|
||||
self.filename = tempfile.mktemp(suffix='.wav')
|
||||
|
||||
def on_filename(self, *args):
|
||||
self.wf = wave.open(self.filename, 'wb')
|
||||
|
||||
def on_voice_src(self, *args):
|
||||
audio_profile = self.voice_src.audio_profile()
|
||||
self.wf.setnchannels(audio_profile['channels'])
|
||||
self.wf.setsamplewidth(audio_profile['sample_size'])
|
||||
self.wf.setframerate(audio_profiel['sample_rate'])
|
||||
self.voice_src.bind(on_fps=self.write)
|
||||
|
||||
def write(self, o, d):
|
||||
if self.saving:
|
||||
self.wf.write(''.join(d))
|
||||
|
||||
def start(self):
|
||||
if not self.voice_src.recording:
|
||||
self.voice_src.start()
|
||||
self.saving = True
|
||||
|
||||
def stop(self):
|
||||
self.saving = False
|
||||
wf.close()
|
@ -1,5 +1,5 @@
|
||||
from traceback import print_exc
|
||||
import ujson as json
|
||||
import json
|
||||
from kivy.properties import StringProperty
|
||||
from kivy.factory import Factory
|
||||
from .toolbar import Toolbar
|
||||
|
@ -1,67 +0,0 @@
|
||||
|
||||
import kivy
|
||||
import numpy as np
|
||||
from .micphone import Micphone
|
||||
from kivy.uix.camera import Camera
|
||||
from kivy.properties import NumericProperty
|
||||
from kivy.event import EventDispatcher
|
||||
|
||||
from .android_rotation import *
|
||||
|
||||
if kivy.platform in [ 'win', 'linux', 'macosx' ]:
|
||||
from PIL import ImageGrab
|
||||
class ScreenWithMic(Micphone, EventDispatcher):
|
||||
def __init__(self, **kw):
|
||||
super(ScreenWithMic, self).__init__(**kw)
|
||||
|
||||
def get_image_data(self):
|
||||
image = ImageGrab.grab()
|
||||
imgdata = image.tostring()
|
||||
return imgdata
|
||||
|
||||
def get_fps_data(self, *args):
|
||||
ad = super(CameraWithMic, self).get_fps_data()
|
||||
vd = self.get_image_data()
|
||||
d = {
|
||||
'v':vd,
|
||||
'a':ad
|
||||
}
|
||||
return d
|
||||
|
||||
VS={
|
||||
ROTATION_0:270,
|
||||
ROTATION_90:0,
|
||||
ROTATION_180:90,
|
||||
ROTATION_270:180,
|
||||
}
|
||||
class CameraWithMic(Micphone, Camera):
|
||||
angle = NumericProperty(0)
|
||||
def __init__(self, **kw):
|
||||
super(CameraWithMic, self).__init__(**kw)
|
||||
self.isAndroid = kivy.platform == 'android'
|
||||
self.set_angle(-90)
|
||||
|
||||
def set_angle(self, angle):
|
||||
self.angle = angle
|
||||
|
||||
def image_rotation(self):
|
||||
if not self.isAndroid:
|
||||
return
|
||||
x = get_rotation()
|
||||
self.angle = VS[x]
|
||||
|
||||
def get_image_data(self):
|
||||
image = np.frombuffer(self.texture.pixels, dtype='uint8')
|
||||
image = image.reshape(self.texture.height, self.texture.width, -1)
|
||||
imgdata = image.tostring()
|
||||
return imgdata
|
||||
|
||||
def get_fps_data(self, *args):
|
||||
# self.image_rotation()
|
||||
ad = super(CameraWithMic, self).get_fps_data()
|
||||
vd = self.get_image_data()
|
||||
d = {
|
||||
'v':vd,
|
||||
'a':ad
|
||||
}
|
||||
return d
|
@ -1,84 +0,0 @@
|
||||
from threading import Thread, Lock
|
||||
import pyaudio
|
||||
from kivy.event import EventDispatcher
|
||||
from kivy.properties import NumericProperty, ObjectProperty
|
||||
from kivy.clock import Clock
|
||||
import wave
|
||||
CHUNK = 1024
|
||||
CHANNELS = 2
|
||||
FORMAT = pyaudio.paInt16
|
||||
samplerate = 48000
|
||||
|
||||
class Micphone(EventDispatcher):
|
||||
channels = NumericProperty(2)
|
||||
samplerate = NumericProperty(48000)
|
||||
fps = NumericProperty(1/60)
|
||||
def __init__(self, **kw):
|
||||
super(Micphone, self).__init__(**kw)
|
||||
self.chunk = CHUNK
|
||||
self.format = pyaudio.Int16
|
||||
self.chunk_buffer = []
|
||||
self.lock = Lock()
|
||||
self.recoding = False
|
||||
self._audio = puaudio.PyAudio()
|
||||
self._mic = p.open(format=self.format,
|
||||
channels=self.channels,
|
||||
rate=self.samplerate,
|
||||
input=True,
|
||||
frames_per_buffer=self.chunk)
|
||||
self.sampe_size = self.audio.get_sample_size(self.format)
|
||||
self.register_event_type('on_fps')
|
||||
self.register_event_type('on_start')
|
||||
self.register_event_type('on_end')
|
||||
self.fps_task = None
|
||||
|
||||
def on_fps(self, d):
|
||||
print('on_fps fired')
|
||||
|
||||
def on_start(self):
|
||||
print('on_start fired')
|
||||
|
||||
def on_end(self):
|
||||
print('on_end fired')
|
||||
|
||||
def audio_profile(self):
|
||||
return {
|
||||
'channels':self.channels,
|
||||
'sample_size':self.sample_size,
|
||||
'sample_rate':self.samplerate
|
||||
}
|
||||
|
||||
def get_frames(self, *args):
|
||||
d = self.get_fps_data()
|
||||
self.dispatch('on_fps', d)
|
||||
|
||||
def get_fps_data(self, *args):
|
||||
self.lock.acquire()
|
||||
d = self.chunk_buffer[:]
|
||||
self.chunk_buffer = []
|
||||
self.lock.release()
|
||||
return d
|
||||
|
||||
def start(self, *args):
|
||||
self.recording = True
|
||||
Background(self._record)
|
||||
self.dispatch('on_start')
|
||||
self.fps_task = Clock.schedule_interval(self.get_frames, self.fps)
|
||||
|
||||
def _record(self):
|
||||
self.recording = True
|
||||
while self.recording:
|
||||
data = self._mic.read(self.chunk)
|
||||
self.lock.acquire()
|
||||
self.hunk_buffer.append(data)
|
||||
self.lock.release()
|
||||
|
||||
def stop(self, *args):
|
||||
self.recording = False
|
||||
self.fps_task.cancel()
|
||||
self.dispatch('on_end')
|
||||
|
||||
def close(self):
|
||||
self._mic.stop_stream()
|
||||
self._mic.close()
|
||||
self._audio.close()
|
@ -31,9 +31,9 @@ from .markdown import Markdown
|
||||
from .defaultimage import *
|
||||
from .price import *
|
||||
|
||||
if kivy.platform in ['win','linux', 'macosx']:
|
||||
from .camerawithmic import ScreenWithMic
|
||||
from .camerawithmic import CameraWithMic
|
||||
#if kivy.platform in ['win','linux', 'macosx']:
|
||||
# from .camerawithmic import ScreenWithMic
|
||||
#from .camerawithmic import CameraWithMic
|
||||
from .scrollpanel import ScrollPanel
|
||||
from .udp_widget import UdpWidget
|
||||
from .paging import PageLoader
|
||||
@ -44,8 +44,8 @@ from .price import PriceView
|
||||
from .ffpyplayer_video import FFVideo
|
||||
|
||||
r = Factory.register
|
||||
if kivy.platform in ['win','linux', 'macosx']:
|
||||
r('ScreenWithMic', ScreenWithMic)
|
||||
# if kivy.platform in ['win','linux', 'macosx']:
|
||||
# r('ScreenWithMic', ScreenWithMic)
|
||||
r('DateInput', DateInput)
|
||||
r('HTTPSeriesData', HTTPSeriesData)
|
||||
r('HTTPDataHandler', HTTPDataHandler)
|
||||
@ -53,7 +53,7 @@ r('PageLoader', PageLoader)
|
||||
r('UdpWidget', UdpWidget)
|
||||
r('ScrollPanel', ScrollPanel)
|
||||
r('TextInput', TextInput)
|
||||
r('CameraWithMic', CameraWithMic)
|
||||
# r('CameraWithMic', CameraWithMic)
|
||||
# r('CustomCamera', CustomCamera)
|
||||
# r('QrReader', QrReader)
|
||||
r('Markdown', Markdown)
|
||||
|
@ -7,4 +7,8 @@
|
||||
# fix bug in __init__.py, can not import kivy here
|
||||
# __version__ = '0.2.11'
|
||||
# move all the source using opencv to a independent module
|
||||
__version__ = '0.2.12'
|
||||
# __version__ = '0.2.12'
|
||||
# move code using pyaudio to a independent module
|
||||
# __version__ = '0.2.13'
|
||||
# use json replace ujson because kivy-ios can not compile ujson
|
||||
__version__ = '0.2.14'
|
||||
|
8
setup.py
8
setup.py
@ -26,7 +26,7 @@ package_data = {
|
||||
'ttf/*.ttf',
|
||||
'ui/*.uidesc',
|
||||
'xcamera/xcamera.kv',
|
||||
'image_processing/cascades/haarcascade_frontalface_default.xml',
|
||||
# 'image_processing/cascades/haarcascade_frontalface_default.xml',
|
||||
'xcamera/data/*'
|
||||
],
|
||||
}
|
||||
@ -48,11 +48,11 @@ setup(
|
||||
],
|
||||
packages=[
|
||||
'kivyblocks',
|
||||
'kivyblocks.image_processing',
|
||||
# 'kivyblocks.image_processing',
|
||||
'kivyblocks.mapview',
|
||||
'kivyblocks.uitype',
|
||||
'kivyblocks.widgetExt',
|
||||
'kivyblocks.xcamera'
|
||||
'kivyblocks.widgetExt'
|
||||
# 'kivyblocks.xcamera'
|
||||
],
|
||||
package_data=package_data,
|
||||
keywords = [
|
||||
|
Loading…
Reference in New Issue
Block a user