#!/usr/bin/env python3
# -*- 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):
        print(e)
        print('stopped')
        vv.Logout()
        stream.close()
        break

temp=re.match("[\u4E00-\u9FA5]*音乐",text1)

if temp!=None:
    print("进入播放音乐模式")
    #!/usr/bin/python3
    # -*- coding: utf-8 -*-

    import viVoicecloud as vv  #导入模块

    t = vv.tts() #实例化

    t.say(text="你要英文还是中文?",voice="xiaofeng")
    while True:
        # -*- coding: utf-8 -*-
        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()
Beispiel #3
0
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()
tts=vv.tts()
tr=vv.baidu_translate()
while True:
	try:
		#接收语音信息,等待“开炮”
		ASR.SessionBegin(language='Chinese')
		stream.start_stream()
		print('***Listening...')

		status=0
		while status!=3:
			frames=stream.read(int(Sample_rate*time_seconds),exception_on_overflow=False)
			ret,status,recStatus=ASR.AudioWrite(frames)
	
		stream.stop_stream()
		print('----GetResult...')