device_in = findDevice("ac108","input") Sample_channels = 1 Sample_rate = 16000 Sample_width = 2 time_seconds = 0.5 p = pyaudio.PyAudio() stream = p.open( rate=Sample_rate, format=p.get_format_from_width(Sample_width), channels=Sample_channels, input=True, input_device_index=device_in, start=False) vv.Login() ASR=vv.asr() while True: try: import pyaudio import viVoicecloud as vv from sjtu.audio import findDevice device_in = findDevice("ac108","input") Sample_channels = 1 Sample_rate = 16000 Sample_width = 2 time_seconds = 0.5 #录音片段的时长,建议设为0.2-0.5秒 p = pyaudio.PyAudio() stream = p.open(
# -*- coding: utf-8 -*- """ Created on Tue Jul 9 23:24:31 2019 @author: apple """ import pyaudio, sys import viVoicecloud as vv import urllib, json, vlc, time import urllib.request p = pyaudio.PyAudio() vv.Login() t = vv.tts() ASR = vv.asr() tr = vv.baidu_translate() t = vv.tts() def findDevice(name, type): p = pyaudio.PyAudio() num = p.get_device_count() for i in range(0, num): device = p.get_device_info_by_index(i) if (device['maxInputChannels'] > 0 and type == 'input' and device['name'] == name): return device['index'] elif (device['maxOutputChannels'] > 0 and type == 'output' and device['name'] == name): return device['index']