replace wave duration with SOX

This commit is contained in:
Your Name 2019-05-11 17:31:00 +02:00
parent d305abe5ae
commit a73ddf59d1

View file

@ -13,6 +13,7 @@ import faulthandler
from zmq.asyncio import Context from zmq.asyncio import Context
import zmq import zmq
import wave import wave
import sox
from pythonosc import udp_client from pythonosc import udp_client
import random import random
@ -1418,10 +1419,15 @@ class Story(object):
fn = await message.getAudioFilePath() fn = await message.getAudioFilePath()
# get duration of audio file, so the client can detect a hang of 'play' # get duration of audio file, so the client can detect a hang of 'play'
with wave.open(fn,'r') as fp:
frames = fp.getnframes() #old: with wave
rate = fp.getframerate() # with wave.open(fn,'r') as fp:
duration = frames/float(rate) # frames = fp.getnframes()
# rate = fp.getframerate()
# duration = frames/float(rate)
# get duration of audio file, new: with sox
duration = sox.file_info.duration(fn)
# self.hugvey.google.pause() # pause STT to avoid text events while decision is made # self.hugvey.google.pause() # pause STT to avoid text events while decision is made
self.hugvey.sendCommand({ self.hugvey.sendCommand({