Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从android识别器获取实时数据?_Android_Kotlin_Speech Recognition_Speech To Text - Fatal编程技术网

如何从android识别器获取实时数据?

如何从android识别器获取实时数据?,android,kotlin,speech-recognition,speech-to-text,Android,Kotlin,Speech Recognition,Speech To Text,我想调用RecognizerIntent并让它永远循环,直到用户决定关闭它,我将如何执行此操作?只要在识别出输入后声音停止,当前的android识别器就会关闭。例如:如果识别出“hi”,如果用户在这之后大约一两秒钟没有说任何话,活动将关闭。我能阻止活动结束吗?直到我选择关闭它为止(也许是第二次点击按钮?) 我还想获取实时数据,以了解所说的内容,而不是在活动结束后将其作为额外数据传递 package com.example.myapplication import android.app.Act

我想调用
RecognizerIntent
并让它永远循环,直到用户决定关闭它,我将如何执行此操作?只要在识别出输入后声音停止,当前的android识别器就会关闭。例如:如果识别出“hi”,如果用户在这之后大约一两秒钟没有说任何话,活动将关闭。我能阻止活动结束吗?直到我选择关闭它为止(也许是第二次点击按钮?)

  • 我还想获取实时数据,以了解所说的内容,而不是在活动结束后将其作为额外数据传递

    package com.example.myapplication
    
    import android.app.Activity
    import android.content.Intent
    import androidx.appcompat.app.AppCompatActivity
    import android.os.Bundle
    import android.speech.RecognizerIntent
    import android.widget.Toast
    import kotlinx.android.synthetic.main.activity_recordinit.*
    import java.lang.Exception
    import java.util.*
    
    class Recordinit : AppCompatActivity() {
    
     val   REQUESTCODE3 = 4
    
    
    
    fun audioaction(){
        val speechtotextintent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        speechtotextintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.EXTRA_LANGUAGE_MODEL)
        speechtotextintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE , Locale.getDefault())
        speechtotextintent.putExtra(RecognizerIntent.EXTRA_PROMPT , "Click To Begin Listening on the threat!!")
        try {
            //check to see if the activity can work on this device... and it meets the requirements
            startActivityForResult(speechtotextintent , REQUESTCODE3 )
    
    
        }
        //if there is any errors we will let the user know in a popup message.
        catch (e : Exception){
            Toast.makeText(this , e.message , Toast.LENGTH_SHORT  ).show()
    
        }
    
    
    
    }
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recordinit)
        microphonebutton.setOnClickListener{
            audioaction()
    
        }
    
    
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    
         if (REQUESTCODE3 == requestCode ){
            when (resultCode == Activity.RESULT_OK ){
    
    
    
            }
    
        }
        super.onActivityResult(requestCode, resultCode, data)
    }
    
    }


  • 编辑:我发现,
    EXTRA\u SPEECH\u INPUT\u COMPLETE\u SILENCE\u LENGTH\u MILLIS
    允许我指定活动对沉默的反应。但我仍然想找到一种方法来实时监控所说的内容。

    也许这有助于您在调用活动时了解所说的内容

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE10) {
            if (resultCode == RESULT_OK && data != null) {
                var result : ArrayList<String> = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
            }
        }
    }
    
    override-on-activityresult(请求代码:Int,结果代码:Int,数据:Intent?){
    super.onActivityResult(请求代码、结果代码、数据)
    if(requestCode==REQUEST\u CODE10){
    if(resultCode==RESULT\u OK&&data!=null){
    变量结果:ArrayList=data.getStringArrayListExtra(RecognizerIntent.EXTRA_结果)
    }
    }
    }